~/tools/json
> json
format and validate json in your browser. pretty-print with 2 or 4 spaces or minify to a single line. syntax errors are shown inline.
## overview
json (javascript object notation) is the default data interchange format on the web. it is a text-based format for structured data: objects, arrays, strings, numbers, booleans, and null. the spec (rfc 8259) is small enough to fit on a postcard, but valid json has subtle rules: double-quoted keys, no trailing commas, no comments, no single quotes, no unquoted keys. this tool parses json with the browser's built-in json parser, so what passes here is what your javascript will parse. errors include the position of the first mistake. formatting options: 2-space indent (common in code), 4-space indent (legible for data dumps), minified (single line for apis). valid inputs are pretty-printed; invalid inputs show the parser error so you can fix them.
## how to use
- paste your json — paste anywhere. the tool parses as you type.
- choose indentation — pick 2 spaces, 4 spaces, or minified. this affects the output only, not validation.
- read the error if any — if the input is invalid, the error shows the problem and often the character offset.
- copy the output — copy the formatted text for use in a file, test fixture, or api request body.
## examples
$ in
{"a":1,"b":[1,2,3]}# out
{
"a": 1,
"b": [
1,
2,
3
]
}$ in
{a:1}# out
error: unexpected token a — keys must be double-quoted strings$ in
{"a":1,}# out
error: unexpected token } — trailing commas are invalid in json## common mistakes
trailing commas— valid in javascript, invalid in json. remove any comma before `]` or `}`.single quotes— json requires double quotes around strings and keys. `'a'` is invalid.comments— json has no comments. `//` and `/* */` will fail to parse. if you need comments, use jsonc (a json superset) — but only tools that explicitly support it will parse it.number edge cases— json numbers cannot be NaN, Infinity, or have leading zeros. `-.5` is invalid; use `-0.5`. very large integers lose precision beyond 2^53.duplicate keys— json technically allows duplicate keys; behaviour depends on the parser. some take the first, some the last. avoid them.
## faq
does this send my json anywhere?
no. parsing runs in your browser via `JSON.parse` and `JSON.stringify`.
what is the size limit?
limited by your browser's string memory and the textarea. roughly a few megabytes is fine; gigabytes are not.
why does my json say 'unexpected token'?
usually a quote, comma, or bracket mismatch. the parser will point at the first problem, but the real mistake is often just before.
can i preserve key order?
yes. JSON.parse and JSON.stringify preserve insertion order per the spec.
does minified json save much?
minified removes whitespace. for typical api payloads, expect 5-30% size reduction.
what about jsonc or json5?
this tool parses strict json (rfc 8259). for jsonc (with comments) or json5 (relaxed syntax), remove those features first or use a dedicated parser.
why do my numbers round?
javascript numbers are ieee 754 doubles; integers above 2^53 − 1 lose precision. if you need exact big integers in json, encode them as strings.