Skip to main content

JSON Validator

Check JSON against the spec and jump to the line of any error

14
Loading editor…

What the validator checks

JSON is stricter than the JavaScript it looks like. A document is valid only if keys and strings use double quotes, items are separated by commas with none after the last item, every bracket and brace is closed, and values are one of: string, number, true, false, null, object or array.

Click Validate and the first error appears with its line and column; click the message to jump to that spot in the editor. Fix it and validate again, because a parser stops at the first problem, so later errors only show once earlier ones are gone. Once the document is valid, Format re-indents it.

The most common JSON errors and how to fix them

These are the mistakes that account for most invalid JSON. The wording is what this validator reports; other parsers phrase the same problems differently.

Trailing comma

Error: Trailing comma in object

Invalid

{
  "a": 1,
  "b": 2,
}

Fixed

{
  "a": 1,
  "b": 2
}

JSON, unlike JavaScript, does not allow a comma after the last item of an object or array. Delete it.

Single quotes

Error: Unexpected token "'"

Invalid

{
  'name': 'Ada'
}

Fixed

{
  "name": "Ada"
}

Only double quotes delimit strings and keys. Replace every single quote that delimits a string.

Unquoted key

Error: Unexpected token "a"

Invalid

{
  name: "Ada"
}

Fixed

{
  "name": "Ada"
}

Object keys must be strings in double quotes, even when they look like plain identifiers.

Missing comma

Error: Unexpected token "b"

Invalid

{
  "a": 1
  "b": 2
}

Fixed

{
  "a": 1,
  "b": 2
}

Two items next to each other need a comma between them. The reported position is the start of the second item.

Comments

Error: Unexpected token "/"

Invalid

{
  // retry count
  "retries": 3
}

Fixed

{
  "retries": 3
}

JSON has no comment syntax. Remove the comments, or keep the notes in a separate field such as "_comment".

undefined or NaN

Error: No value found for key "a"

Invalid

{"a": undefined, "b": NaN}

Fixed

{"a": null, "b": null}

undefined, NaN and Infinity are JavaScript values, not JSON values. Use null, a number or leave the key out.

Validating JSON in your own code

In JavaScript, JSON.parse throws a SyntaxError on invalid input, so wrap it in try/catch when the text comes from a user, a file or a network response. In Python, json.loads raises json.JSONDecodeError with the line and column. When a program reports an "Unexpected token" error, paste the text here to see where it breaks.

This validator checks your text against the JSON specification and points at the first place it breaks. It runs in your browser, so the JSON you paste is never sent to a server.

Frequently Asked Questions

Is my JSON uploaded when I validate it?

No. Validation runs in your browser with client-side JavaScript. The text never leaves your device.

What is the difference between a JSON validator and a JSON formatter?

A validator tells you whether the text is valid JSON and where it is not. A formatter changes its layout (indentation and line breaks) without changing its data. This page does both: Validate reports errors, and Format re-indents valid JSON.

Why does it only show one error at a time?

A JSON parser stops at the first character it cannot make sense of, because everything after it depends on how that character is read. Fix the reported error and validate again to reach the next one.

Does it accept JSON with comments or trailing commas?

No. It validates strict JSON, the format other programs and APIs expect. Files such as tsconfig.json or VS Code settings accept comments only because their own tools parse a looser dialect (JSONC).

Have suggestions or feedback? We're constantly improving FormatChamp based on your comments.