Skip to content
TabShedKitsMy desk

Fix "Invalid JSON" Errors: What Each Message Means and Where to Look

Updated 5 min readBy

Read the error messages of the JSON Parser, such as "Expected a property name in double quotes", and the five mistakes that cause most of them.

JSON ParserParse and explore JSON as a tree
Open JSON Parser
On this page
  1. How the parser reports errors
  2. The messages and what they mean
  3. Five mistakes behind most errors
  4. Step by step
  5. When the JSON is valid but still wrong
  6. Large or hard-to-read JSON
  7. When the error is not in your JSON
  8. Frequently asked questions

You paste a JSON response into a tool and it says "Invalid JSON". The message points to a line and a column, but the real mistake is often a few characters before. This guide translates the messages of the JSON Parser into plain causes and fixes, and shows how to use its tree view to find the problems that are not syntax errors at all.

How the parser reports errors

The parser follows the JSON standard strictly and reports the first place where the text stops being valid, with a line and column, for example "Expected ',' or '}' but found '"' at line 4, column 3". The same message appears in every browser, because the tool does its own check rather than relying on the browser's. Only the first error is shown, so after you fix it, the next one may appear. That is normal: fix, look again.

The important detail is that the error is where the parser noticed the problem, which is often right after the real mistake. If the message says it found something unexpected at line 4, look at the end of line 3 first.

The messages and what they mean

MessageUsual causeFix
Expected a property name in double quotes but found '}'A trailing comma after the last property: {"a": 1,}Remove the comma
Expected a property name in double quotes but found 'x'An unquoted key like {name: 1} or single quotes like {'name': 1}Put double quotes around the key
Expected ':' but found ...A missing colon or a stray character between key and valueAdd the colon
Expected ',' or '}' but found ...A missing comma between two propertiesAdd a comma at the end of the line before
Expected ',' or ']' but found ...A missing comma between array itemsAdd the comma
Unexpected token ']' (or another symbol)A trailing comma in an array: [1, 2,]; or text that is not JSON, such as a comment or undefinedRemove the comma or the extra text
Unexpected token 'x' after the JSON valueExtra text after the JSON ended: two objects side by side, or a stray bracketKeep one value, or wrap several in an array
Unterminated stringA quote that was never closedClose the string
Unescaped control character in stringA real line break or tab inside a stringWrite it as \n or \t
Bad escape character / Bad unicode escapeA backslash followed by a letter that is not an escape, such as a Windows path C:\Users, or a short \u codeDouble the backslash (\\) or use four hex digits
Unexpected end of JSON inputThe text stops too early: a missing closing bracket or brace, or a truncated copyComplete the text

Five mistakes behind most errors

  1. Trailing commas. Allowed in JavaScript, not in JSON. Remove the last comma before a closing } or ].
  2. Single quotes. JSON strings and keys need double quotes. A Python dictionary or JavaScript object printed to the console is not JSON, even if it looks close.
  3. Comments. JSON has none. Config files that allow comments use a related format. Remove the comments before pasting.
  4. Python or JavaScript values. True, False, None, undefined and NaN are not JSON. Use true, false and null, and write NaN as null or a string.
  5. A copied fragment. A response cut off during copying, or log text mixed around the JSON, such as a timestamp before the first brace. Copy from the first { or [ to the matching last one.

Step by step

  1. Paste the text into the left box. It is parsed as you type, so there is no button to press.
  2. If the text is invalid, the message appears under the box and the tree stays empty.
  3. Read the line and column, look at that spot and at the end of the previous line, fix one thing, and look again.
  4. When the JSON is valid, the tree view on the right shows it as a structure of objects and arrays that you can expand and collapse.

When the JSON is valid but still wrong

A valid file is not necessarily the right one. The tree view helps with the other class of problems, the ones that no syntax check can find:

  • A missing field. Expand the object where you expect it and see whether the key is there.
  • The wrong type. A number shown in quotes is text; a count that is the string "5" will fail a strict comparison in code.
  • null where you expected a value. Look for the key and see its value.
  • The wrong nesting. The data you want sits inside another object or array, and your code reads the level above.

If the top-level JSON is only a number, a string, true, false or null, the parser shows it under a single "value" key so the tree can display it.

Large or hard-to-read JSON

For a long single line, format it first with the JSON Formatter: with each key on its own line, a line number in an error message points to something you can find. To compare two JSON documents, sort the keys and compare them in the Text Diff Checker. To get records into a spreadsheet, use the JSON to CSV Converter.

When the error is not in your JSON

  • The response is HTML. A message that begins with Unexpected token '<' means the server returned a web page, often an error page, not JSON. Check the URL and the response status.
  • The file starts with an invisible character. A byte order mark or a zero-width space at the beginning is flagged as an unexpected token. Delete the first character and retype it.
  • The JSON is double-encoded. A string full of backslash quotes is JSON inside a JSON string. Decode the outer layer first.

Frequently asked questions

Is my JSON sent to a server?

No. Parsing happens in your browser and nothing is uploaded.

Why does the tool show only one error?

The parser stops at the first place where the text cannot be valid; fix it and the next one appears if there is one.

Does it accept comments or trailing commas?

No. It follows the JSON standard.

Why is the tree empty?

The box is empty or the JSON is invalid. Look under the input for the message.