Does the Rich Results Test accepting comments make JSON-LD comments valid?

The Citead team, updated

In short. The test may ignore JSON-LD comments, but published JSON-LD should contain valid JSON without comments.

Definition: No. Google's Rich Results Test ignores comments within JSON-LD blocks, but its help page says that this behavior is not supported by the JSON-LD standard and might produce errors in actual usage. A passing test shows that the tool tolerated the syntax; publication still requires conforming JSON-LD.

Key facts

  • Google's Rich Results Test help says the tool supports structured data in JSON-LD, RDFa, and Microdata.
  • The same help page says the test ignores comments within JSON-LD blocks and tells publishers to remove every comment before publishing the final page.
  • The W3C JSON-LD 1.1 specification states that a JSON-LD document is always a valid JSON document.
  • IETF RFC 8259 defines JSON text with a grammar of values, strings, numbers, literal names, structural characters, and insignificant whitespace.

Why can the test accept commented JSON-LD?

The Rich Results Test accepts a code snippet as an input. Google's Rich Results Test help documents that the tool ignores comments inside JSON-LD blocks, so its parser can continue to inspect the structured data after skipping those characters. The tool then reports detected rich result types, errors, or suggestions for the structured data.

Google's documentation labels this as comment support in code blocks. It also warns that the behavior is outside the JSON-LD standard and might cause errors when the data is used elsewhere. The warning describes the test's tolerance; it does not add a JSON-LD syntax rule.

What does the JSON-LD standard require?

JSON-LD 1.1 describes a JSON-LD document as a valid JSON document so that standard JSON libraries can process it. The specification also says that, at the surface level, a JSON-LD document is JSON detailed in RFC 8259. JSON-LD adds its own meaning through keywords such as @context, while retaining the JSON serialization rules.

RFC 8259 describes JSON text as a sequence of tokens. Its grammar makes the permitted value forms explicit:

JSON-text = ws value ws
value = false / null / true / object / array / number / string
member = string name-separator value

The RFC defines insignificant whitespace as spaces, horizontal tabs, line feeds, and carriage returns around structural characters. A comment marker such as // or /* ... */ is not one of the listed JSON values, structural characters, or whitespace forms. It therefore belongs to a parser extension rather than conforming JSON syntax.

What should go on the published page?

Remove comments from the JSON-LD before publishing, even if the Rich Results Test accepts the snippet. Google's help page gives that instruction because the same commented text may produce errors in actual usage. Keep explanatory notes in the source template, deployment documentation, or code comments outside the JSON-LD block, then emit only JSON-LD data in the published block.

The test's support for JSON-LD is still useful for checking the structured data formats and rich result data it recognizes. It does not change the serialization rule documented by W3C and IETF sources.

How can you check a comment issue?

Paste the snippet into the Rich Results Test and record whether the tool reports a syntax error or detects an item. Google's documentation says the test can accept code snippets and report detected items. Then remove the comments and run the same check again. Treat the first result as evidence of the tool's documented tolerance; use the comment-free version as the publication candidate.

FAQ

Can comments remain in JSON-LD because the test accepts them?

No. Google tells publishers to remove comments from JSON-LD before publishing, and the W3C specification describes JSON-LD documents as valid JSON documents.

Does a passing Rich Results Test prove that commented JSON-LD is standard JSON-LD?

No. It proves that this test run tolerated the comments. Google's own help page warns that the behavior is outside the JSON-LD standard and may lead to errors in actual usage.

Are comments a JSON-LD feature?

No. JSON-LD uses JSON as its surface syntax. The JSON grammar in RFC 8259 lists the permitted values and whitespace forms without a comment construct.

Sources

  1. Google Search Console Help, "Rich Results Test", undated
  2. W3C, "JSON-LD 1.1", 16 July 2020
  3. IETF, "The JavaScript Object Notation (JSON) Data Interchange Format", December 2017

Check how a page reads to answer engines. Open the GEO score analyzer

Test a page and see what to fix first

The analysis usually takes less than 10 seconds and needs no account.

400,000+ pages scored in the public benchmark