JSON formatter
Prettify, minify, and validate JSON in your browser with JSON.parse and JSON.stringify. 2-space pretty print, nothing uploaded.
JSON formatting parses and re-serializes JSON using JSON.parse and JSON.stringify. Prettify adds 2-space indentation for readability. Minify removes all whitespace for compact storage. Validate checks syntax and shows a pass/fail badge. Standard JSON only (RFC 8259) — no comments, trailing commas, or unquoted keys. Large integers may lose precision due to JavaScript number limits. Nothing is uploaded.
How it works
- Paste or type JSON. The input accepts any text.
- Click Prettify, Minify, or Validate. Each button runs
JSON.parseto check syntax, thenJSON.stringifyto format. Prettify uses 2-space indentation. Minify removes whitespace. Validate shows the badge and formatted JSON. - Copy or review. Valid JSON appears in the result box. Invalid JSON shows an error message with the parse failure.
Common JSON errors
- Trailing commas before
}or] - Comments (
//or/* */) - Single-quoted strings
- Unquoted object keys
- Leading zeros on numbers (
01) - Hex numbers (
0xFF) - Raw newlines inside strings (use
\n)
Format JSON in Python and Node
The snippets below parse one JSON text and write it back — 2-space pretty print or compact minify — the same JSON.parse / JSON.stringify path this page uses. Standard JSON only (RFC 8259): no comments, trailing commas, or unquoted keys. For Unicode when minifying, see Minify JSON Without Breaking Unicode.
Node.js with JSON.parse and JSON.stringify
Node uses the same ECMA-262 methods as this page. JSON.stringify(data, null, 2) matches Prettify. JSON.stringify(data) matches Minify. Invalid JSON throws SyntaxError. Integers larger than 253 − 1 lose precision because JSON.parse uses IEEE-754 binary64:
const compact = '{"name":"Docify","count":2}';
const data = JSON.parse(compact);
const pretty = JSON.stringify(data, null, 2);
// 2-space indent — same as this page's Prettify
const minified = JSON.stringify(data);
// {"name":"Docify","count":2}Python with json.loads and json.dumps
CPython json.loads keeps integers exact (arbitrary precision). json.dumps(..., indent=2) matches this page's 2-space Prettify. The default compact form still inserts spaces after : and , — pass separators=(',', ':') to match Minify. Default ensure_ascii=True writes non-ASCII as \uXXXX; this page's JSON.stringify keeps those characters. Pass ensure_ascii=False to match. Invalid JSON raises json.JSONDecodeError:
import json
compact = '{"name":"Docify","count":2}'
data = json.loads(compact)
pretty = json.dumps(data, indent=2, ensure_ascii=False)
# 2-space indent — same as this page's Prettify
minified = json.dumps(data, separators=(',', ':'), ensure_ascii=False)
# {"name":"Docify","count":2}Non-ASCII such as café stays a character in Node, this page, and CPython with ensure_ascii=False. Default CPython writes caf\u00e9. CPython json.loads accepts the non-RFC tokens NaN and Infinity; JSON.parse rejects them. Default json.dumps writes those tokens; pass allow_nan=False to raise ValueError instead. JSON.stringify of a JavaScript NaN writes null. python -m json.tool pretty-prints with 4-space indent by default — not this page's 2-space Prettify. Neither snippet is JSONC, JSON5, or YAML.
JSON in the shell
Prettify and Minify on this page parse one RFC 8259 JSON value with JSON.parse and write it back with JSON.stringify — 2-space indent, or compact with no spaces after : and ,. CPython's stdlib CLI python3 -m json.tool (json.tool; Python 3.14 also accepts python3 -m json) uses the same json.loads / json.dumps path as the Python block above. The default indent is 4 spaces, not this page's 2-space Prettify. Python 3.9+ --indent 2 matches Prettify; --compact matches Minify. --no-indent still inserts spaces after : and ,. There is no POSIX json pretty-printer. jq is a separate package (2-space indent by default) and is not this CLI. These commands are standard JSON, not JSONC, JSON5, or YAML.
CPython json.tool
Reads a file or stdin and writes to stdout. RFC 8259 allows trailing whitespace, so echo is fine for a complete JSON value. Invalid JSON prints the decode error to stderr and exits 1:
# Default: 4-space indent (not this page's 2-space Prettify)
printf '%s' '{"name":"Docify","count":2}' | python3 -m json.tool
# Python 3.9+: 2-space indent (same as this page's Prettify)
printf '%s' '{"name":"Docify","count":2}' | python3 -m json.tool --indent 2
# Python 3.9+: compact (same as this page's Minify)
printf '%s' '{"name":"Docify","count":2}' | python3 -m json.tool --compact
# {"name":"Docify","count":2}Default encode writes non-ASCII as \uXXXX; Python 3.9+ --no-ensure-ascii keeps café as a character, matching this page. json.tool appends a trailing newline after the last }; this page's JSON.stringify does not. Integers larger than 253 − 1 stay exact (arbitrary precision); JSON.parse uses IEEE-754 binary64. json.loads accepts the non-RFC tokens NaN and Infinity; JSON.parse rejects them. Default dumps writes those tokens back. --sort-keys (3.5+) reorders object keys; this page keeps parse order. --json-lines (3.8+) is NDJSON — one value per line. This page formats one JSON value. Older CPython (before 3.9) has no --indent, --compact, or --no-ensure-ascii. macOS does not ship python3 by default; Homebrew installs it. Windows uses py -m json.tool when the Python launcher is installed. For the json.dumps options in a script, use the Python block above. Unicode when minifying is covered in Minify JSON Without Breaking Unicode.
Format JSON with jq
There is no POSIX JSON pretty-printer. jq 1.7 . copies one JSON value and writes it back — 2-space pretty print by default, the same indent Prettify uses on this page. -c / --compact-output drops the spaces after : and ,, matching Minify. The filter can be omitted; jq then uses .. jq is not POSIX. For the CPython stdlib CLI, see JSON in the shell above.
jq . and jq -c .
Read a file or stdin. RFC 8259 allows trailing whitespace, so echo is fine for a complete JSON value. Invalid JSON prints the parse error to stderr and exits 5. jq appends a trailing newline after the last }; this page's JSON.stringify does not:
# Default: 2-space indent (same as this page's Prettify)
printf '%s' '{"name":"Docify","count":2}' | jq .
# {
# "name": "Docify",
# "count": 2
# }
# Compact (same as this page's Minify, plus a trailing newline)
printf '%s' '{"name":"Docify","count":2}' | jq -c .
# {"name":"Docify","count":2}
printf '%s' '{"name":"café"}' | jq -c .
# {"name":"café"}
printf '%s' '{name:Docify}' | jq .
# jq: parse error: Invalid numeric literal at line 1, column 6Tokens JSON.parse rejects
jq 1.7 accepts a few non-RFC tokens that JSON.parse on this page rejects. Leading zeros and a leading + become numbers. NaN writes null — the same token JSON.stringify writes for a JavaScript NaN, but this page never parses that input. Infinity writes 1.7976931348623157e+308 (IEEE-754 max). CPython json.tool writes the NaN token back:
printf '%s' '{"n":01}' | jq -c .
# {"n":1}
printf '%s' '{"n":+1}' | jq -c .
# {"n":1}
printf '%s' '{"n":NaN}' | jq -c .
# {"n":null}
printf '%s' '{"n":Infinity}' | jq -c .
# {"n":1.7976931348623157e+308}
printf '%s' '{"n":9007199254740993}' | jq -c .
# {"n":9007199254740993}Integers larger than 253 − 1 stay as that decimal in jq 1.7; JSON.parse uses IEEE-754 binary64, so 9007199254740993 becomes 9007199254740992 on this page. -S / --sort-keys reorders object keys; this page keeps parse order. --ascii-output writes non-ASCII as \uXXXX; default jq keeps café, matching this page. --indent n sets spaces (max 7); --indent 0 is compact; --tab uses tabs. jq reads a stream of JSON values, so two objects back-to-back or NDJSON print as two results; this page formats one value. -s slurps inputs into one array. -R treats each line as a string, so the compact object above becomes a JSON string — do not pass it when you want Prettify. -r only unwraps JSON strings; it does not change object formatting. Trailing commas, comments, unquoted keys, single quotes, and 0xFF still fail. Empty input writes nothing and exits 0. None of these commands are JSONC, JSON5, or YAML — convert YAML on the YAML to JSON converter. jq @csv belongs on the JSON to CSV converter. Unicode when minifying is covered in Minify JSON Without Breaking Unicode.
FAQ
- Does this formatter upload my JSON?
- No. All formatting runs in your browser using JSON.parse and JSON.stringify. Your JSON is never sent to a server.
- What is the difference between Prettify, Minify, and Validate?
- Prettify formats JSON with 2-space indentation. Minify removes all whitespace to create compact output. Validate checks syntax and displays the Valid or Invalid badge. All three use JSON.parse under the hood.
- Why did my large number change after formatting?
- JSON.parse converts numbers to JavaScript Numbers (IEEE-754 binary64). Integers larger than 2^53 − 1 lose precision. Keep exact IDs or large numbers as JSON strings to preserve them.
- Why does a trailing comma fail validation?
- Standard JSON (RFC 8259) does not allow trailing commas before } or ]. Unlike JavaScript, you must remove the final comma after the last element.
- Why do comments fail validation?
- Standard JSON has no comment syntax. Slashes are valid only inside strings. Use JSONC or JSON5 tools if you need comments.
- Can I format JavaScript object literals?
- No. Unquoted keys, single quotes, trailing commas, functions, and undefined are not valid JSON. Convert the text to strict JSON first.
Related
- How to Format JSON Online: Parse and Prettify
- Validate JSON Syntax with JSON.parse
- JSON vs YAML: Configuration Files
- Minify JSON Without Breaking Unicode
- Need to export JSON to a spreadsheet? Use the JSON to CSV converter.
- Sibling tools: YAML to JSON, CSV to JSON, Unicode NFC / NFD, and URL encoder
- All developer tools