~/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.

indent:
$ output
error: empty input

## 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

  1. paste your jsonpaste anywhere. the tool parses as you type.
  2. choose indentationpick 2 spaces, 4 spaces, or minified. this affects the output only, not validation.
  3. read the error if anyif the input is invalid, the error shows the problem and often the character offset.
  4. copy the outputcopy the formatted text for use in a file, test fixture, or api request body.

## examples

$ example 1 — pretty-printed with 2-space indent
$ in
{"a":1,"b":[1,2,3]}
# out
{
  "a": 1,
  "b": [
    1,
    2,
    3
  ]
}
$ example 2 — invalid
$ in
{a:1}
# out
error: unexpected token a — keys must be double-quoted strings
$ example 3 — trailing comma
$ in
{"a":1,}
# out
error: unexpected token } — trailing commas are invalid in json

## common mistakes

  • trailing commasvalid in javascript, invalid in json. remove any comma before `]` or `}`.
  • single quotesjson requires double quotes around strings and keys. `'a'` is invalid.
  • commentsjson 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 casesjson numbers cannot be NaN, Infinity, or have leading zeros. `-.5` is invalid; use `-0.5`. very large integers lose precision beyond 2^53.
  • duplicate keysjson 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.

## related tools

  • base64 encode and decode base64 strings (client-side, unicode-safe).
  • url codec percent-encode and decode URL components.

## references

  1. RFC 8259 — json data interchange format
  2. MDN — JSON.parse
  3. MDN — JSON.stringify
ad slot · tool-json