OnlineTextLab
Esc

JSON Validator

A clear verdict on your JSON, the spot where it breaks, and what to change.

Result

The verdict appears here. If something is wrong, you get the line, the column and how to fix it.

Runs on your device. Your files and text are not uploaded.

About JSON Validator

When a deploy fails with "Unexpected token" or a config file will not load, you need to know two things: is this valid, and if not, where exactly is it wrong? Paste the text and the answer appears as you type, with the offending line shown and a caret under the character.

Valid JSON can still cause trouble, so a pass here goes further than a green tick. Duplicate keys and integers too long for JavaScript are both legal syntax, and both lose data once a program reads them. Those get flagged as worth checking, next to counts of the objects, arrays and keys in the document.

How it works

The text goes through a hand-written parser that follows the JSON grammar strictly, because browser error messages differ and are often vague. The parser recognizes common mistakes by what they look like: a single quote, a True from Python, a leading zero in 007, an undefined from JavaScript, a comment. Each gets a message that names the fix.

When a bracket is left open, it reports the line where that object or array began, which is usually more helpful than the last line of the file. On a long minified line the excerpt is trimmed around the error so the caret stays on screen.

How to use JSON Validator

  1. Paste into the JSON to check box, or press Upload to open a file. Try an example loads a sample with a deliberate mistake.
  2. Read the result. An error names the line and column, and marks the character.
  3. For valid JSON, look at the counts: objects, arrays, keys, scalar values, deepest nesting and size.
  4. Press Copy or Download to keep the report as json-validation.txt.

A trailing comma, pinpointed

Input
{
  "service": "billing",
  "regions": ["eu-west-1", "us-east-1",],
  "enabled": true
}
Output
Line 3, column 40: a trailing comma is not allowed before "]". Remove the last comma.

  "regions": ["eu-west-1", "us-east-1",],
                                       ^

JavaScript accepts that comma, so the file may look fine in your editor. The JSON standard (RFC 8259) does not allow it, and strict parsers in other languages will reject it.

When it helps

  • Finding out why a package.json or tsconfig-style file stopped loading after a hand edit
  • Checking a webhook payload before blaming the code that received it
  • Confirming that a file generated by a script is well formed before it ships
  • Spotting a key that got pasted twice during a merge

Tips for a better result

  • Fix the first error and check again. A missing quote early on can make later lines look wrong, so working from the top is quicker.
  • A message about a raw line break inside a string usually means a closing quote is missing, not that the text needs escaping.
  • When the problem is structure, not syntax, the deepest nesting figure is a quick sanity check against what you expected to receive.

Good to know

  • It checks syntax only. It cannot tell you whether a field is required or a value has the right type, which takes JSON Schema and a schema validator.
  • Comment-friendly variants such as JSONC and JSON5 are reported as invalid, because they are not JSON. A tsconfig.json with comments is fine for its compiler and still fails here.
  • It stops at the first syntax error, so a file with several mistakes needs several passes.
  • The Upload button takes files up to 5 MB. For anything bigger, paste the text.

Questions people ask

Is a single value such as 42 valid JSON?

Yes. Since RFC 7159, a JSON document can be any value, not only an object or array. The report calls it a single number value.

Are duplicate keys valid JSON?

The grammar allows them, and the standard only says names should be unique. This tool reports the document as valid and warns you, since most parsers silently keep the last value.

Why does my file work in JavaScript but fail here?

JavaScript object syntax is looser. Unquoted keys, single quotes, trailing commas and comments all work in code, and none of them are allowed in JSON.

Why am I warned about a number that is valid?

Integers beyond 2^53 - 1 cannot be held exactly by JavaScript, so JSON.parse in a browser returns a rounded value. The syntax is fine, but the data would change in transit.

What to use next

Learn more

Last reviewed . Read our editorial policy.