JSON Formatter & Validator

Paste JSON to pretty-print it with 2 or 4 spaces, minify it to one line, or sort its keys. If it is invalid, the validator shows the line and column of the first error and the usual reason, such as a trailing comma or single quotes. Everything runs in your browser.

JSON syntax rules

  • Strings and object keys use double quotes: "name", never 'name'.
  • No trailing commas: [1, 2, 3,] is invalid.
  • Values are strings, numbers, true, false, null, objects or arrays. No undefined, functions, NaN or dates.
  • No comments.
  • Special characters in strings are escaped: \", \\, \n, \t, é.

Format JSON in code

JSON.stringify(JSON.parse(text), null, 2);   // pretty-print
JSON.stringify(JSON.parse(text));            // minify

# Command line
jq . data.json
python -m json.tool data.json

Frequently asked questions

Why is my JSON invalid?

The most common causes are a trailing comma after the last item, single quotes instead of double quotes, keys without quotes, comments, and unescaped line breaks inside strings. JSON is stricter than JavaScript object syntax: none of those are allowed.

Can JSON have comments?

No. Standard JSON (RFC 8259) has no comments. Formats such as JSONC (used by VS Code settings) and JSON5 allow them, but a standard JSON parser will reject them.

Is my JSON uploaded anywhere?

No. Formatting and validation use the browser’s built-in JSON.parse and JSON.stringify, so your data never leaves the page.

What does sort keys do?

It rewrites every object with its keys in alphabetical order, at every level. That makes two JSON documents with the same data in a different order easy to compare.

Related tools