Your JSON is broken and you cannot see where

You pasted some JSON and it will not parse. The error gives a number, or nothing at all, and the text is one long line. This page shows what Express Lint does about that, and what it leaves alone.

Why it is hard to find

  • One long line

    JSON copied from an API response or a log often has no line breaks. All you see is a wall of text.

  • A count, not a place

    Chrome, Edge and Node give a character count, such as position 24. You count 24 characters from the start. Newer versions add a line and column too, but on one line the line is 1.

  • Safari gives none

    Safari says JSON Parse error: Expected '}' and nothing more. There is no position to count.

What Express Lint does

Press Validate & Format on text that will not parse, and the validator does four things.

  1. It breaks the text into indented lines, so you can find the error.
  2. It changes only spaces and line breaks outside strings. A string in single or double quotes is copied as written. When it cannot tell what is a string, it leaves your text alone.
  3. It marks the line where JSON.parse stops, and boxes the character it stopped on.
  4. Ctrl+Z gives your text back.

If the quotes do not pair up, it leaves your text as it is.

Repair stays your choice. Nothing is fixed unless you turn on repair or press Try repair.

Before and after

One document with a comma missing after "Ada". On the left it is as you pasted it. On the right it is what the validator shows after Validate & Format.

pasted.jsonFails to parse
{"id": 7, "name": "Ada" "email": "ada@example.com", "tags": ["a", "b"], "active": true}
JSON.parse stops at position 24, on line 1.

Express Lint adds line breaks and spaces. Nothing else changes.

formattedStill fails
{
  "id": 7,
  "name": "Ada" "email": "ada@example.com",
  "tags": [
    "a",
    "b"
  ],
  "active": true
}
Only line breaks and spaces changed. JSON.parse stops at line 3, column 17.

Now the mistake is easy to see. Line 3 holds two members, "name" and "email", with no comma between them. Every other member has a line to itself. JSON.parse stops on the quote that starts "email".

Then fix it

Add the comma after "Ada" and the document parses. Or press Try repair. It is the button that appears after a failed check. It rewrites the document with the fix and lays it out with indentation. For this example it adds the missing comma.

Try repair rewrites the document, so read the result before you keep it.

Common errors

Most broken JSON is one of a few mistakes. Each page has a broken example, a fixed one, and the message as each runtime prints it.

Try it yourself

The button opens this example in the validator and checks it, so you see it formatted. Press Ctrl+Z in the editor to get the one-line text back.

The example travels in the URL fragment, which browsers never send to a server.

What you put into the tools never leaves your browser. We count page views and keep them for 90 days. Accept and we also remember this browser, so a return visit is not counted as new. Privacy policy