How to validate JSON and find the exact error line

A validator tells you whether a document is syntactically valid. A useful one also tells you where the problem is. This guide covers the five failure modes we see most often, how to read a parser error, and two JSON pitfalls that no validator will warn you about.

The five errors that break JSON most often

Every one of these produces a parser failure, but the message is only useful if you know what it points at. The table below maps the common messages to their usual cause.

Error in the sourceTypical parser messageFix
Trailing comma after the last itemUnexpected token } in JSONRemove the final comma
Single-quoted key or valueUnexpected token 'Use double quotes
Unquoted keyUnexpected token i in JSON at position 4Wrap the key in double quotes
// or /* */ commentUnexpected token / in JSONDelete the comment
Missing comma between membersUnexpected string in JSONAdd a comma after the previous value

In hand-edited configuration files, trailing commas and unquoted keys are the two most common causes of a failed parse. Check both before spending time reading the rest of the message.

How to locate the error in three steps

  1. Click Validate in the JSON Formatter and read the reported position. The tool converts the browser parser's character index into an approximate line and column by counting newline characters before that index.
  2. Jump to that position in your editor. If the document is minified, format it first — on a single line every error is technically on line 1, which tells you nothing useful.
  3. Fix the first reported error and validate again. Parsers stop at the first failure, so a second error is often waiting behind the one you just fixed.

The three-step loop matters because a single pass rarely reaches the end of a badly edited file. Re-running validation is faster than scanning the document by eye.

Two things a validator will not tell you

Duplicate keys are legal JSON. An object containing the same key twice parses successfully, and the last value wins without a warning. If a setting appears to be ignored, search the document for the key before blaming the application.

Large integers lose precision. JavaScript represents every number as a 64-bit float, so integers above 2^53 cannot be stored exactly. An 18-digit order ID may come back with its final digits changed even though validation passed. Store identifiers as strings.

Neither case is a syntax error. A validator passes both documents while the data is wrong, which is why a clean validation result is necessary but not sufficient.

When to format, minify and validate

Use Format for configuration files and API samples you need to read. Use Minify for transport and storage — removing whitespace typically cuts a pretty-printed document by 20 to 40 percent. Use Validate before committing hand-edited JSON. Format also validates, so a separate validation pass is only needed when you want the exact error position rather than readable output.

Frequently asked questions

Does JSON allow comments?

No. JSON has no comment syntax. A parser stops at the first slash outside a string. Remove // and /* */ comments before validating, or switch to a format such as JSONC or YAML that supports them.

Can I validate JSON that uses single quotes?

No. JSON requires double quotes around both keys and string values. JavaScript object literals often use single quotes, which is why pasting one into a validator fails.

Why does validation pass but my app reads the wrong value?

Two common causes: duplicate keys, where the last value silently wins, and integers above 2^53, which lose precision because the number is stored as a 64-bit float. Neither is a syntax error.

Is there a size limit for validation?

There is no fixed limit in the tool. Practical size depends on browser memory, and documents of several megabytes normally work. Format very large single-line files before looking for an error position.

Use the JSON Formatter →

Page last reviewed: