JSON Formatter & Validator
Validate, pretty-print or minify JSON.
About JSON Formatter & Validator
A JSON formatter and validator checks that text is valid JSON, names the line of the first error, and prints it with 2 or 4 spaces or minified.
How to use
- Paste JSON, or load a
.jsonor.txtfile of up to 5 MB by choosing it or dropping it on the page. Validation runs as you type. - Pick the output: 2 spaces (default), 4 spaces or Minify.
- Read the status line. Valid JSON reports the top-level shape, for example "3 keys" or "12 items". Invalid JSON shows the parser's message and, when the browser reports a position, the line number.
- Copy the result or Download it as
.json, named after the loaded file when there is one.
What it supports
- Parses with the browser's
JSON.parse, so it follows RFC 8259 exactly: double-quoted keys, no trailing commas, no comments, no single quotes. - Re-serialises with
JSON.stringify, which removes all original whitespace and prints keys in their original order. Numbers are printed as JavaScript numbers, so1.0becomes1and integers above 2^53 lose precision. - The error line is taken from the parser message; some browsers only report a position, which is converted to a line, and some report neither.
- Does not sort keys, fix errors or check the document against a JSON Schema.
Example
{"name":"xutil","tags":["json","tool"]}
→ 2 spaces
{
"name": "xutil",
"tags": [
"json",
"tool"
]
}
Privacy
Parsing and formatting run in the browser. No request is made, and nothing is stored.
Frequently asked questions
- Why is my JSON invalid when it looks fine?
- The usual causes are a trailing comma after the last item, single quotes instead of double quotes, an unquoted key, or a comment. JSON (RFC 8259) allows none of these, even though JavaScript does.
- What is the difference between JSON formatting and minifying?
- Formatting adds line breaks and indentation so people can read the structure; minifying removes every optional space and newline so the file is smaller to send. The data is identical either way.
- Does JSON allow comments?
- No. The JSON specification has no comment syntax, so a parser rejects // and /* */. Some configuration formats such as JSONC and JSON5 add comments, but standard JSON.parse will not accept them.
- Why did a large number change after formatting?
- JavaScript stores numbers as 64-bit floats, so integers above 9,007,199,254,740,991 (2^53 − 1) cannot be represented exactly and are rounded when the JSON is parsed and re-printed. Keep such values as strings if precision matters.