Developer

How to find and fix JSON syntax errors

Use a formatter to pinpoint invalid JSON and check common problems such as trailing commas, comments, and unescaped quotes.

Open JSON Formatter

A JSON parser usually stops at the first place it cannot continue. That point can be a few characters after the actual mistake. A formatter helps you locate the problem, but fixing the document is easiest if you check the characters just before the reported position.

Reproduce a small error

Paste this into JSON Formatter and choose Format:

{
  "project": "Workshop",
  "supplies": ["paper", "markers",],
  "open": true
}

The comma after "markers" says another array item is coming. The next character closes the array, so remove the comma and try again. Once the input is valid, the formatted output puts each level of nesting on its own indented lines.

Check the usual suspects

  • Property names need double quotes. A key such as project works in a JavaScript object literal but must be written as "project" in JSON.
  • A literal double quote inside a string must be escaped. For example, write "She said \"hello\"".
  • Comments and trailing commas are invalid in standard JSON. Some configuration files use a JSON variant that permits them. Check the format expected by the program that reads your file.
  • Booleans are lowercase. Write true and false without quotes when you want boolean values.

Fix one error at a time and format again. If the error moves, the parser may have progressed further into the document.

Check what the receiving program expects

Passing a syntax check means the text is valid JSON. The receiving application can still reject it if it expects an array and gets an object, or if a field has the wrong type. Compare the formatted output with a working example from that application. If you changed more than a couple of lines, open the original and the corrected text in Text Compare to check what you changed before replacing the original.

Reduce a large payload to the part that fails

Keep the original and make a working copy. If the parser reports a line near the end of a large array, inspect the preceding object and the separator between the two. A missing comma between objects can look like a problem on the next opening brace. An unmatched quote can also make otherwise valid braces appear to be part of a string.

To isolate a problem, copy one complete object into a separate editor and validate that object by itself. When removing surrounding items, keep the remaining opening and closing brackets paired. If the object passes on its own, add the adjacent item and check the boundary between them.

Check which layer owns the escaping

JSON inside another string can have two levels of escaping. A log entry may print a JSON string with backslashes even when the underlying API response is valid. Test the raw response body or an exported file if you can, rather than copying a display that has already escaped it. A text file with smart quotes around property names also needs straight double quotes before it can be parsed.

Once the document parses, run the same operation that failed originally. A formatted copy on screen is useful, but the original client or importer determines whether the payload is usable. For project files and repeated checks, compare the options in Best JSON formatters and validators.

  • JSON
  • validation
  • debugging

Ready to try it?

JSON Formatter is free to use and runs in your browser.

Try JSON Formatter
Esc