toolready. JSON Formatter & Validator

JSON Formatter & Validator

Pretty-print, minify, and validate JSON with precise error pointers.

What this does

Paste JSON into the input box and press one of three buttons. Format pretty-prints it at 2 spaces, 4 spaces or a tab depending on the Indent dropdown. Minify collapses it to a single line and reports the resulting character count. Validate parses and says nothing more than whether it worked. All three go through the browser's own JSON.parse and JSON.stringify, in the page, so production payloads and tokens never leave the machine you are on.

How do I pretty-print JSON?

  1. Paste the raw JSON — a minified API response, a log field, anything — into Input.
  2. Pick an indent width.
  3. Click Format. The result lands in the read-only Output box below.
  4. Click Copy, or Clear to empty both boxes and start again.
input   {"a":1,"b":[2,3]}
format  {
          "a": 1,
          "b": [
            2,
            3
          ]
        }

Where exactly is my JSON invalid?

When the parse fails, the red bar between the boxes gives you the engine's message with a location appended, for example Unexpected token , (line 2, column 8). The line and column are computed here: the byte offset the JavaScript engine reports is converted by counting newlines up to that point, so column 1 is the first character of the line. Browsers that report a failure without an offset — most commonly Unexpected end of JSON input, which is what you get from an unterminated string or a missing closing brace — fall back to line 1, column 1. In that case the message itself is the signal: something is unclosed, so check the end of the document rather than the start. The output box is emptied on any error, so a stale result never sits there looking valid.

Why am I getting "Unexpected token"?

  • A trailing comma after the last element of an array or object.
  • Single quotes — JSON strings are double-quoted, always.
  • An unquoted key: {name: "x"} must be {"name": "x"}.
  • A // or /* */ comment.
  • Values copied out of JavaScript: undefined, NaN, Infinity and +1 are all rejected.
  • A leading byte-order mark or a wrapping callback(…) from an old JSONP endpoint.

Does formatting change my data?

It re-serializes rather than reflows, so a few things are normalised on the way through. Duplicate keys collapse to the last one that appeared. Numbers come back in JavaScript's canonical form — 1.0 becomes 1, 1e3 becomes 1000, and an integer beyond 2^53 (a Snowflake ID, say) loses precision because it was never held exactly. Unicode escapes such as \u00e9 are resolved to the character itself, and keys that look like non-negative integers are moved to the front in numeric order. For everything else — string content, nesting, ordinary key order — the round trip is faithful, and formatting then re-minifying gets you back exactly where you started.

Can JSON have comments or trailing commas?

Not in the standard, and JSON.parse enforces it, so both are errors here. If your file is a config that genuinely needs them, it is JSONC or JSON5, and you need to strip the extras before feeding it to a strict parser. A pragmatic alternative is to keep the file in YAML or TOML, which support comments natively, and convert with the JSON/YAML/TOML converter. Related: turn a response into an interface with JSON to TypeScript, flatten it for a spreadsheet with CSV to JSON, or decode a bearer token's payload with the JWT decoder.