How do I format JSON?
Reviewed by Prabath Thalangama · Last updated
Paste minified or messy JSON and the formatter parses it and prints it back with two-space indentation, one key per line, so nested objects and arrays are easy to read. Because it parses the input first, it also tells you when the JSON is invalid. Everything runs in your browser; nothing is uploaded.
The formatter uses the browser's standard JSON parser, which follows RFC 8259 strictly. That is the same parser web applications use, so if it is accepted here it will be accepted by JSON.parse in your code.
Strict parsing has two side effects worth knowing. Numbers beyond 2^53 (9007199254740992) lose precision when parsed, which matters for 64-bit IDs. And if an object repeats a key, only the last value survives.
How do I use the JSON formatter?
- Paste the JSON into the input box.
- Format it. Valid JSON appears indented in the output; invalid JSON shows the parser's error message.
- Copy the formatted result, or fix the reported problem and format again.
How to read the results
- Formatted output
- The same data, re-serialized with two-space indentation. Key order is kept, except that keys that look like whole numbers ("1", "42") move to the front, a JavaScript object quirk.
- Error message
- The parser's reason for rejecting the input. Most browsers include the position or line of the problem.
Common JSON errors and how to fix them
Trailing comma
JSON does not allow a comma after the last item in an object or array.
{"a": 1, "b": 2,} // invalid
{"a": 1, "b": 2} // validSingle quotes or unquoted keys
Keys and strings must use double quotes. JavaScript object literals are not JSON.
{name: 'web'} // invalid
{"name": "web"} // validComments
Standard JSON has no comments. Remove them, or use a format that allows them (JSON5, JSONC or YAML) where the consuming tool supports it.
NaN, Infinity or undefined
These JavaScript values are not valid JSON. Use null or a string instead.
Large IDs change after formatting
Integers above 2^53 cannot be represented exactly. Send 64-bit IDs as strings, as the Twitter/X and Discord APIs do.
Examples and command-line equivalents
Format JSON on the command line
jq . data.json
python3 -m json.tool data.json
# From an API response
curl -s https://api.example.com/items | jq .Minify (the reverse)
jq -c . data.jsonFrequently asked questions
Is my JSON uploaded anywhere?
No. Parsing and formatting happen in your browser with JavaScript, so it is safe to format configuration files and API responses that contain internal data.
Why does the formatter say my JSON is invalid when my app accepts it?
Your app may use a lenient parser that accepts comments, trailing commas or single quotes. This formatter applies the JSON standard (RFC 8259), which rejects them.
Can I change the indentation?
The output uses two spaces. To use tabs or four spaces, run jq --indent 4 . or python3 -m json.tool --indent 4 on the command line.