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.
- It lays the text out by bracket depth. A line break and an indent go after
{,[and,, and before}and]. - 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.
- It marks the line where
JSON.parsestops, and boxes the character it stopped on. - 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.
{"id": 7, "name": "Ada" "email": "ada@example.com", "tags": ["a", "b"], "active": true}Express Lint adds line breaks and spaces. Nothing else changes.
{
"id": 7,
"name": "Ada" "email": "ada@example.com",
"tags": [
"a",
"b"
],
"active": true
}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.
- Expected ',' or '}' after property value in JSON
JSON.parseread a value, and the next character was not a comma or a closing brace. - Trailing comma in JSONA comma separates two values.
- Single quotes in JSONJSON defines exactly one string delimiter: the double quote.
- Unexpected end of JSON inputYour JSON stopped early.
- Bad control character in string literal in JSONA JSON string cannot hold a raw line break or tab.
- Unexpected token '<', "<!DOCTYPE "... is not valid JSONYour code asked for JSON and got an HTML page instead.
- All JSON errorsEvery common way JSON.parse fails, in JavaScript, Python, Java, PHP, Go and C#.
Try it yourself
The button opens this example in the validator and checks it, so you see the layout happen. 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.