Start building

Guides

"Invalid JSON in tag 'schema'": how to find the broken character

Shopify tells you the JSON is broken and often doesn't say where. A browser console will tell you the line and column, and there are only about ten things it can be.

The Klorr teamUpdated 10 min read

  • Schema
  • JSON
  • Errors
  • Debugging

Key takeaways

  • Paste the schema's contents into your browser console inside JSON.parse to get the line and column of the first problem.
  • The usual causes are a trailing comma, a missing comma, curly quotes from a pasted document, an unescaped quote in a default, or a comment.
  • Liquid inside a quoted string is valid JSON and won't raise this error, but Shopify doesn't render it either, so it shows as literal text.
  • Duplicate setting ids are valid JSON. They pass this check and then fail Shopify's schema rules with a different message.

Here's a schema that won't save. It has four kinds of mistake, each among the most common. See how many you can spot before reading on.

A broken schema, for practice
{% schema %}
{
  "name": "Promo band",
  "settings": [
    { "type": "text", "id": "heading", "label": "Heading", "default": "Winter sale" }
    { "type": "text", "id": "note", "label": “Note” },
    // the button
    { "type": "url", "id": "link", "label": "Link", },
  ]
}
{% endschema %}

In order: no comma after the first setting, curly quotes around Note, a // comment, and trailing commas after "Link" and after the last setting. Fix one, and the next reveals itself. It helps to know that JSON parsers stop at the first error, so "still broken" after a fix may be real progress.

Get the exact position in under a minute

Your browser's own parser can point at the character, and this works in Chrome or Edge on any computer, with nothing to install.

  1. Copy only the JSON

    Select from the first { after {% schema %} to the last } before {% endschema %}. Don't include the Liquid tags.

  2. Open the console

    On any page, press F12, or Cmd+Option+J on a Mac, and click Console.

  3. Run it through JSON.parse

    Use the one-line wrapper shown under these steps, with your JSON pasted in place of the dots, and press Enter. Chrome may ask you to type "allow pasting" first.

  4. Read the message

    You'll get something like Expected ',' or '}' after property value in JSON at position 212 (line 6 column 5). Line 1 is the first line of your JSON, as long as the paste starts straight after the opening backtick.

  5. Fix and repeat

    Correct that spot in your copy and run it again. When the console prints an object and no error, your JSON is valid.

script.js
JSON.parse(String.raw`...paste here...`)

String.raw keeps any backslashes in your defaults exactly as written, so an escaped quote reaches the parser unchanged. If you work on themes locally, Shopify's Theme Check has a ValidSchema check for this, which runs in shopify theme check and in the VS Code extension. A failed save doesn't touch your store: Shopify rejects the file and the last saved version keeps running, so take your time. Keep your text copied somewhere in case you close the tab.

Every cause, with the console message

These are the messages current Chrome and Node versions give for each mistake when it goes through JSON.parse. Other browsers word them differently. Note that a parser reports the place it got confused, which is often just after the actual mistake.

Message starts withUsual causeLook for
Expected double-quoted property nameTrailing comma before }, or a /* */ comment after a commaA comma on the line above the position
Unexpected token ']'Trailing comma before ]The last item in settings, blocks or presets
Expected ',' or '}' after property valueMissing comma between properties, or an unescaped " in a stringEnd of the previous value. Check defaults containing HTML
Expected ',' or ']' after array elementMissing comma between two settings} followed by { on the next line
Expected property name or '}'A curly quote or single quote on a key, a // comment, Liquid outside a string, or a non-breaking spaceThe first characters at that position; retype them
Unexpected token '“' or '''Curly or single quotes around a valueText pasted from Word, Docs, a chat app or a web page
Bad control character in string literalA real line break or tab inside a stringA default that runs over two lines
Unexpected non-whitespace character after JSONAn extra } at the end, or a second objectBracket count, or something between the last } and {% endschema %}

Trailing commas

JavaScript allows them, and JSON doesn't. Deleting the last setting while leaving its comma behind on the one above is the usual way to get here, and Shopify's own docs use this as their failing example for the check.

schema.json
"settings": [
  { "type": "text", "id": "heading", "label": "Heading" },
  { "type": "url", "id": "link", "label": "Link" }
]

Curly quotes and invisible spaces

Copying a schema from a document, a chat tool, or some blog themes can turn " into “ and ”. They look nearly identical in many fonts. The same paths can introduce a non-breaking space where a normal space should be, which is invisible and gives you an error on what looks like a perfect line. Retype the line, or use your editor's find and replace with regular expressions to search for [“”‘’] and \u00A0. The Shopify code editor's search panel supports regular expressions.

A double quote inside a default

This is the cause that catches experienced developers, because HTML in a richtext default feels normal:

schema.json
{ "default": "<p>See <a href="/pages/returns">returns</a></p>" }

{ "default": "<p>See <a href=\"/pages/returns\">returns</a></p>" }

The first line breaks at the second ", since JSON thinks the string ended there. Escape it with a backslash as in the second line. Single quotes in the HTML attribute also work (<a href='/pages/returns'>) and read more easily. While you're there, Shopify's setting rules expect a richtext default's top level to be <p> or <ul>.

Line breaks inside a string

A JSON string has to stay on one line. If a textarea default needs several lines, write \n between them. A tab inside a string needs \t for the same reason. Tabs for indenting between properties are fine.

Comments

// and /* */ aren't part of JSON. If you need notes for yourself, put them in a Liquid comment above the schema tag, or say it to the merchant in a header setting or in info text, where it's useful to someone.

Liquid in the schema

The schema documentation says the tag doesn't render any Liquid inside it. What happens depends on where you put it:

You wroteIs it valid JSON?What happens
"default": {{ shop.name }}No, it's unquotedThis error
"default": "{{ shop.name }}"Yes, it's a stringIt passes as JSON, and Shopify never fills it in, so a merchant would see the braces as plain text
{% if x %} wrapped around a settingNoThis error, or a syntax error
{% schema %} inside {% if %}Not a JSON matterA syntax error: the schema tag can't be nested in another Liquid tag

A schema is static, so you can't make it vary by product or by plan. Settings can be read by Liquid in the rest of the file, so build the variation out there: {{ section.settings.heading | default: shop.name }}.

Mismatched brackets

If you've been cutting and pasting blocks, count them. A setting's { needs its }, settings needs its ], and the object needs a closing }. Most code editors highlight the matching bracket when your cursor sits next to one. Formatting the JSON, which indents each level, makes a misplaced bracket visible at a glance, because the indentation stops looking right at that spot.

Things that look like this error and aren't

Once the JSON parses, Shopify checks it against its rules for sections, which is where the message changes. JSON.parse will happily accept all of these. So if the console prints your object and Shopify still complains, you've left JSON problems behind and are on to schema problems.

  • Two settings with "id": "heading" are perfectly good JSON because they're separate objects. Shopify wants ids unique within the section or the block, and refuses with a message naming the problem.
  • "type": "string" isn't one of the setting types, and there's no date type either.
  • A range needs numeric min, max and default, and these can't be strings. A default is required.
  • Preset blocks can break your own limits, such as three blocks of a type whose limit is 1.
  • A block or preset can be missing its name.
  • A section can have only one, and a second is a syntax error.
  • Unknown tag 'endschema' means the opening tag is damaged. See the Liquid error reference for this and other non-JSON messages.
  • New schema is incompatible with the current setting value means the JSON is valid and saved template data no longer fits it, typically after a removed option or block type.

A section that saves but doesn't appear in the Add section list is a different problem again, usually no presets. This troubleshooting guide walks through it.

Stop it happening again

  • Edit in a code editor that highlights JSON errors, rather than in a notes app or document.
  • Copy code from a code block's copy button when one exists. Avoid copying from a page's rendered text, a PDF or a slide.
  • Add new settings at the top or middle of an array. Fewer edits at the end means fewer stray commas.
  • Change one thing per save, so when it fails you know what did it.
  • Generate the schema when you don't need to write it by hand. The section schema generator builds it in your browser, with the JSON already valid and nothing sent to a server.

If you'd rather not write schemas at all, Klorr writes a whole section from a description; the Liquid code generator page shows a sample. And when you do write your own, how to make a section editable covers which setting type fits which job.

Questions, answered

What does Invalid JSON in tag schema mean in Shopify?

The text between {% schema %} and {% endschema %} in your section isn't valid JSON, so Shopify won't save the file. It's usually one wrong character, such as a stray comma or a curly quote.

How do I find where the JSON error is?

Copy only the JSON from the schema and run it through JSON.parse in your browser's console. Chrome reports the line and column of the first problem. Fix it and repeat until no error appears.

Can I use Liquid inside a Shopify section schema?

No. Shopify doesn't render Liquid inside the schema tag. Unquoted, it breaks the JSON. Quoted, it stays literal text. Read the setting in the section's markup and use Liquid there, such as with the default filter.

Can I put comments in a Shopify schema?

No, JSON has no comments. Use a Liquid comment outside the schema tag for your notes, or a header setting or info text for notes aimed at the merchant.

Do duplicate setting ids cause Invalid JSON in tag schema?

No. Duplicate ids are valid JSON, so they pass this stage. Shopify then rejects them under its own schema rules with a different message. Ids must be unique within a section and within each block.

Did my store break when this error appeared?

No. The file failed to save, so your store keeps running the last version that did save. Nothing changes for customers until a save succeeds.

Get the whole section written for you

Describe the section you want. Klorr writes the Liquid, the CSS, the schema and every theme-editor setting — code that lives in your theme and stays yours.