Skip to content
SeenLens

JSON-LD syntax error: how to find and fix it

A JSON-LD syntax error means the text inside the script tag is not valid JSON, so parsers skip the whole block. Typical causes are a trailing comma, single quotes, an unescaped quote in a value and a template placeholder left in. SeenLens fails the page and prints the parse error. Most fixes take under ten minutes.

By SeenLens · Last updated

Run the free 43-check scan on your page

What does the JSON-LD parse check test?

SeenLens reads each JSON-LD block in the page HTML and tries to parse it as JSON. The check has four outcomes.

JSON-LD parse check results
SituationResult
The page has no JSON-LD blockNot applicable
At least one block does not parseFail. The evidence names the block number and the parse error.
A block was too large to checkWarn
Every block parsesPass

The check tests syntax only. A block can parse and still use wrong property names or miss properties that Google needs. Test those with the Rich Results Test or the Schema Markup Validator.

Google says structured data should match what visitors see, and its tools report errors in Search Console. A block that cannot be parsed gives search engines nothing to use. No study shows a link between a syntax error and AI citations.

How do I find the broken block?

Run this script. It fetches the page, extracts every JSON-LD block and prints the parse error with its position.

Terminal
curl -s https://example.com/page | python3 -c '
import sys, re, json
html = sys.stdin.read()
blocks = re.findall(r"<script[^>]*application/ld\+json[^>]*>(.*?)</script>", html, re.S | re.I)
print(len(blocks), "JSON-LD blocks")
for i, b in enumerate(blocks, 1):
    try:
        json.loads(b); print(i, "ok")
    except ValueError as e:
        print(i, "ERROR:", e)
'

An error such as Expecting ',' delimiter: line 7 column 3 points to the line inside that block. Line 1 is the first line after the opening script tag.

Which mistakes cause the error?

Common JSON-LD syntax mistakes
MistakeWrongRight
Trailing comma"name": "A",}"name": "A"}
Single quotes'name': 'A'"name": "A"
Unescaped quote in a value"name": "The "Best" Shop""name": "The \"Best\" Shop"
Line break inside a stringA value that runs onto the next lineUse \n or keep it on one line
Comment// logoRemove it. JSON has no comments.
Curly quotes from a document“name”"name"
Template placeholder left in"price": {{ price }}Fill it in on the server
Two objects side by side{...}{...}Use two script tags, or one @graph array

How do I fix it?

Build the JSON from data in code, not from hand written strings. A serializer escapes quotes and line breaks for you.

Next.js

Create the object in code and call JSON.stringify. Escape the < character as the Next.js docs advise, so a value that contains a closing script tag cannot break the page.

TypeScript
const json = JSON.stringify(jsonLd).replace(/</g, "\\u003c");
// <script type="application/ld+json" dangerouslySetInnerHTML={{ __html: json }} />

WordPress

Find which source prints the broken block: your SEO plugin, a schema plugin, the theme or a Custom HTML block. Turn the sources off one at a time and rerun the script. Fix or remove the broken one. If you pasted a block from a word processor or chat tool, replace curly quotes with straight quotes.

Shopify

Liquid inserts text as it is. A product title with a double quote breaks the string. Use the json filter, which outputs a quoted and escaped JSON string.

Liquid
"name": {{ product.title | json }},
"description": {{ product.description | strip_html | json }},

Static sites

Paste the block into a JSON validator or run the script above, fix the reported line and repeat until every block says ok. Generate the block from front matter with your site generator's JSON filter when you can.

How do I verify the fix?

  1. Run the script again. Every block must print ok.
  2. Test the URL in the Rich Results Test and the Schema Markup Validator to catch schema errors.
  3. Scan the page with SeenLens. The check must pass.

When can I ignore this check?

Do not ignore a failure. A broken block is dead weight. If the block is not yours, such as one injected by a widget, remove the widget or ask the vendor to fix it. A page with no JSON-LD at all gets 'not applicable' here and fails the presence check instead.

Scan your page with SeenLens

Common questions

How do you fix a syntax error in JSON-LD?

Find the block and line from the parser message. Fix the missing comma, extra comma, quote or bracket on that line. Run the parser again until every block is ok.

Is a JSON-LD block that parses also valid for Google?

Not always. Parsing only proves the JSON is well formed. Google's Rich Results Test checks that the types and properties fit the feature you want.

Sources