DoH JSON: 5 Differences Between Cloudflare and Google
In this article
This guide explains how to read the JSON responses from DNS-over-HTTPS (DoH) services and highlights five key differences between Cloudflare's and Google's implementations. You'll learn the structure of the responses, what each field means, and how the two providers differ in their JSON schemas, cache behavior, and error handling. No prior experience with DoH is required, but familiarity with JSON and basic DNS concepts will help.
What You'll Need
- A web browser or a tool like
curlto make HTTPS requests. - Basic understanding of DNS records (A, AAAA, MX, etc.).
- Optional: a JSON viewer or
jqfor pretty-printing responses.
Step-by-Step
- Make a DoH query to Cloudflare. Use the endpoint
https://cloudflare-dns.com/dns-querywith the parameter?name=example.com&type=A. Include the headerAccept: application/dns-jsonto get JSON. For example, in a terminal:curl -H 'Accept: application/dns-json' 'https://cloudflare-dns.com/dns-query?name=example.com&type=A'. The response will be a JSON object with fields likeStatus,Answer, andQuestion. - Make the same query to Google. Use
https://dns.google/resolvewith the same parameters and header. For example:curl -H 'Accept: application/dns-json' 'https://dns.google/resolve?name=example.com&type=A'. The response will look similar but with some differences you'll spot in the following steps. - Compare the top-level fields. Both return a
Statusfield (the DNS response code, e.g., 0 for NOERROR),Question(the query echoed back), andAnswer(array of records). However, Cloudflare includes aflagsfield (e.g.,flags: ["qr", "rd", "ra"]) that Google does not. Google includesCommentin some error responses (e.g., when a domain doesn't exist), which Cloudflare does not. - Examine the Answer array structure. Each answer object in both services contains
name,type,TTL, anddata. Thedatafield holds the record value (e.g., an IP address). One difference: Cloudflare returns theTTLas an integer (e.g.,300), while Google also returns it as an integer, but Google includes an additionalexpirationfield (a timestamp when the record expires) in some cases, which Cloudflare omits. - Check the
Statuscodes and error handling. Both use standard DNS response codes. However, when a query fails (e.g., NXDOMAIN), Google returns aStatusof 3 and includes aCommentfield like "No such name". Cloudflare returns the sameStatusbut does not include aComment. Additionally, for malformed queries, Google returns a JSON withStatus: 0and an emptyAnswer, while Cloudflare returns an HTTP 400 error with a plain text message like "Invalid request". - Look at the
Questionfield. Both echo back the query, but Cloudflare includes atypefield as an integer (e.g.,1for A), while Google also uses an integer. The difference is that Google includes thenamein the question exactly as sent (preserving case), while Cloudflare lowercases it. For example, queryingExample.COMwill echoExample.COMin Google'sQuestionbutexample.comin Cloudflare's. - Compare the
AD(Authentic Data) flag handling. Both services include anADflag in theflagsarray (Cloudflare) or as a boolean fieldad(Google). Cloudflare includesad: truein theflagsarray when DNSSEC is validated, while Google includes a separateadfield with a boolean value. This is a structural difference: Cloudflare puts it in theflagslist, Google has a dedicated field. - Check the
CD(Checking Disabled) flag. Similarly, Cloudflare includescdin theflagsarray, while Google has a separatecdfield. This is consistent with the AD flag difference. - Note the HTTP caching headers. While not part of the JSON body, the HTTP response headers differ. Cloudflare includes
Cache-Control: max-age=300based on the TTL, while Google includesCache-Control: public, max-age=300and also setsDateandExpiresheaders. This affects how you might cache responses on your side. - Test with a non-existent domain. Query
nonexistent.example.comto see the error format. Cloudflare returnsStatus: 3(NXDOMAIN) with an emptyAnswer, while Google returnsStatus: 3and aCommentfield: "No such name". This is a clear difference in error reporting.
Common Mistakes
- Not setting the Accept header. Both services require
Accept: application/dns-jsonto return JSON; otherwise they return wire-format DNS (binary). - Assuming identical schemas. As shown, Cloudflare and Google have subtle differences in fields like
flagsvs.ad/cdand the presence ofCommentin errors. - Ignoring the
Statusfield. Always checkStatusbefore parsingAnswer; a non-zero status means the answer may be empty or incomplete. - Misinterpreting TTL values. TTL is in seconds, not milliseconds. Some developers mistakenly treat it as milliseconds.
Tips
- Use
jqto pretty-print JSON for easier reading:curl ... | jq . - For automation, normalize the JSON by converting Cloudflare's
flagsarray into booleans foradandcdto match Google's format. - When caching responses, use the
Cache-Controlheader from the HTTP response rather than the TTL in the JSON, as it may be adjusted by the provider. - Test with different record types (AAAA, MX, TXT) to see how the
datafield varies; for TXT records, the data is a string with quotes.
Troubleshooting
- Getting a binary response instead of JSON: Ensure you set the
Accept: application/dns-jsonheader. If using a browser, you may need to use a tool like curl or a browser extension that sets custom headers. - HTTP 400 error from Cloudflare: This usually means the query parameters are malformed. Check that
nameis a valid domain andtypeis a valid DNS record type (e.g., A, AAAA, MX). - Google returns
Status: 0but emptyAnswer: This can happen if the query is valid but the record type is not supported (e.g., type=ANY). Google may return an empty answer with aCommentexplaining the issue. - Fields missing in the response: If you don't see
flagsorad, check the HTTP status code. Some errors return a minimal JSON with onlyStatusandComment. - TTL differences between providers: Cloudflare and Google may return different TTLs for the same record due to their caching policies. This is normal; the TTL is the time-to-live from the authoritative server, but the resolver may cap it.
Frequently Asked Questions
What is DNS-over-HTTPS (DoH)?
DoH is a protocol that sends DNS queries over HTTPS, encrypting the data to prevent eavesdropping and tampering. Both Cloudflare and Google offer public DoH resolvers that return JSON responses when requested.
Why do Cloudflare and Google have different JSON structures?
Each provider implements the DoH standard (RFC 8484) but adds their own extensions. Cloudflare includes a flags array, while Google uses separate boolean fields for AD and CD. Error handling also differs, with Google providing a Comment field.
Can I use the same code to parse both responses?
Yes, if you write code that checks for the presence of fields. For example, check if flags exists and parse it, otherwise look for ad and cd fields. The core fields (Status, Question, Answer) are identical.
What does the Status field mean?
It's the DNS response code. 0 means NOERROR (success), 3 means NXDOMAIN (domain doesn't exist), 2 means SERVFAIL, etc. Always check this before using the Answer.
How do I get the IP address from the Answer array?
Look for objects in the Answer array where type is 1 (A) or 28 (AAAA). The data field contains the IP address. For other types, data contains the record value (e.g., a hostname for MX).
Are these differences documented officially?
Yes. Cloudflare's documentation describes the flags field, and Google's documentation mentions the ad and cd fields. However, the exact behavior may change, so it's best to test with live queries.