JSON formatter and validator

Paste JSON to beautify it, minify it or find exactly where it's broken.

This tool runs in your browser. We never send what you type or paste to a server.

Common JSON errors

  • Trailing commas: {"a": 1,} is valid JavaScript but not valid JSON.
  • Single quotes: JSON strings and keys must use double quotes.
  • Unquoted keys: {a: 1} must be {"a": 1}.
  • Comments: standard JSON has no comments. Remove // and /* */.
  • Special values: undefined, NaN and Infinity aren't allowed; use null or a string.

Example

Paste a one-line API response:

{"id":7,"tags":["admin","beta"],"active":true}

Format with 2 spaces gives:

{
  "id": 7,
  "tags": [
    "admin",
    "beta"
  ],
  "active": true
}

Minify turns it back into a single line, which is what you want in an environment variable or a curl command.

What the formatter checks

JSON is defined by RFC 8259: six kinds of value (object, array, string, number, true/false, null), strings in double quotes, and nothing else. This page reads your text with its own strict parser rather than JSON.parse, so it can report the line and column of the first problem, notice repeated keys, and print numbers exactly as you typed them. Formatting only changes the whitespace between tokens; minifying removes it. The data itself is never rewritten.

Format and validate JSON in code

JavaScript / Node.js: JSON.stringify(value, null, 2) pretty-prints, and passing an array of key names as the second argument picks and orders keys.

const text = '{"id":7,"tags":["admin","beta"],"active":true}';
const data = JSON.parse(text);                  // throws SyntaxError on invalid JSON
console.log(JSON.stringify(data, null, 2).split('\n').length);   // → 8   lines once pretty-printed
console.log(JSON.stringify(data));              // → {"id":7,"tags":["admin","beta"],"active":true}
console.log(JSON.stringify({ b: 1, a: 2 }, ['a', 'b']));          // → {"a":2,"b":1}   key list picks and orders keys (top level only here)

Python: json.dumps takes indent, sort_keys and separators. Note that it escapes every non-ASCII character unless you pass ensure_ascii=False, and that its error object carries the line and column.

data = json.loads('{"id":7,"tags":["admin","beta"],"active":true}')
print(json.dumps(data, separators=(',', ':')))      # → {"id":7,"tags":["admin","beta"],"active":true}
print(json.dumps({"b": 1, "a": 2}, sort_keys=True))  # → {"a": 2, "b": 1}
print(json.dumps({"city": "Málaga"}).isascii())      # → True   by default á is written as a \uXXXX escape
print(json.dumps({"city": "Málaga"}, ensure_ascii=False))   # → {"city": "Málaga"}
try:
    json.loads('{"a": 1,}')
except json.JSONDecodeError as e:
    print(e.msg, e.lineno, e.colno)                  # → Illegal trailing comma before end of object 1 8   wording of Python 3.13; older versions differ
print(json.loads('{"id": 12345678901234567890}')["id"])     # → 12345678901234567890   Python ints do not round

Shell: Python ships a formatter, python -m json.tool, which exits with a non-zero status on invalid input, so it works as a validator in scripts and CI. --indent and --compact need Python 3.9 or later.

echo '{"id":7,"active":true}' | python -m json.tool --indent 2 | head -2 | tail -1    # → "id": 7,
echo '{"b":1,"a":2}' | python -m json.tool --sort-keys --compact                    # → {"a":2,"b":1}
echo '{"a": 1,}' | python -m json.tool > /dev/null 2>&1 || echo invalid             # → invalid
echo '{"a": 1}'  | python -m json.tool > /dev/null 2>&1 && echo valid               # → valid

PowerShell: ConvertTo-Json only goes two levels deep by default and turns anything deeper into a string, so always pass -Depth.

$data = '{"id":7,"tags":["admin","beta"],"active":true}' | ConvertFrom-Json
$data | ConvertTo-Json -Compress                                     # → {"id":7,"tags":["admin","beta"],"active":true}
$deep = '{"a":{"b":{"c":{"d":1}}}}' | ConvertFrom-Json
$deep | ConvertTo-Json -Compress                                     # → {"a":{"b":{"c":"@{d=1}"}}}   default -Depth is 2
$deep | ConvertTo-Json -Compress -Depth 10                           # → {"a":{"b":{"c":{"d":1}}}}

When a round trip changes your data

This page keeps numbers as text, but most code does not. JSON.parse turns every number into a 64-bit float, which holds integers exactly only up to 253 − 1 (9,007,199,254,740,991). Larger IDs, such as snowflake IDs or 64-bit database keys, come back rounded, and 1.10 comes back as 1.1:

console.log(JSON.parse('{"id": 12345678901234567890}').id);      // → 12345678901234567000
console.log(JSON.parse('{"price": 1.10}').price);               // → 1.1
console.log(JSON.parse('{"a": 1, "a": 2}').a);                  // → 2   the last duplicate wins

If you control the API, send large IDs as strings. Python's json module keeps integers exact, but floats still go through binary doubles.

Questions

Does this upload my JSON?

No. Parsing and formatting happen entirely in your browser.

Can it sort JSON keys?

Yes. Tick "Sort keys" to sort object keys alphabetically at every level, which makes two JSON documents easier to compare.

How big a file can it handle?

Several megabytes is fine on a modern computer. Very large files may take a moment to format.

Does it change my numbers or the order of keys?

No. Numbers are kept exactly as written, so a 19-digit ID or 1.10 comes out unchanged, and keys stay in the order you pasted them unless you tick Sort keys.

What if a key appears twice?

The JSON is still formatted, and a warning names the repeated key and its line. Most parsers keep only the last value, so a duplicate is usually a bug.

Why does my 19-digit ID change after JSON.parse?

JavaScript numbers are 64-bit floats, exact only up to 9007199254740991. A larger integer is rounded to the nearest value a float can hold. This formatter shows the original digits, but your code will see the rounded number unless the ID is sent as a string or read with a big-number JSON library.

Can it format JSON with comments (JSONC) or JSON5?

No. Comments, trailing commas, single quotes and unquoted keys are reported as errors, because standard parsers reject them too. Remove them first, or use a tool that understands your config format (VS Code settings and tsconfig.json accept JSONC).

How do I check that a file is valid JSON in a shell script?

Pipe it through python -m json.tool and test the exit status: python -m json.tool file.json > /dev/null && echo valid. The command prints the parser error and exits non-zero when the JSON is broken.