HandyBench

JSON Formatter & Validator

Beautify, minify and validate JSON.

How to use the JSON Formatter & Validator

  1. 1 Paste your JSON into the editor.
  2. 2 Choose an indent size to pretty-print, or minify to one line.
  3. 3 Fix any errors shown, then copy the formatted JSON.

What counts as valid JSON

JSON is defined by RFC 8259 (and the equivalent ECMA-404). It is deliberately small: objects in curly braces, arrays in square brackets, strings, numbers, true, false and null. This formatter validates by running your input through the browser's own JSON.parse, so anything it accepts is strictly spec-compliant JSON, and the error messages you see are the browser's.

The rules most often broken by hand-written JSON are these.

  • Strings and keys must use double quotes. Single quotes are not valid.
  • No trailing commas after the last item in an object or array.
  • No comments, either // or /* */.
  • No undefined, NaN, Infinity, or unquoted keys; those are JavaScript, not JSON.
  • Numbers cannot have leading zeros (007) or a leading plus sign.

Worked example

Beautifying {"name":"Ada","tags":["a","b"],"n":1.50} with 2-space indentation gives:

{
  "name": "Ada",
  "tags": [
    "a",
    "b"
  ],
  "n": 1.5
}

Each nesting level adds two spaces, so the array items sit four spaces in.

Notice that 1.50 became 1.5. The tool parses and then re-serialises your data, which is what guarantees clean output, but it also means the text is rebuilt rather than reformatted in place. For the invalid input {"a":1,}, Chrome and Node report "Expected double-quoted property name in JSON at position 7 (line 1 column 8)". Position 7 is zero-based, pointing at the closing brace after the stray comma. Other browsers word it differently.

Beautify, minify and indent

Beautify offers 2 spaces, 4 spaces or tabs. Minify removes all optional whitespace to give the smallest valid text, which is useful for config values embedded in code, query parameters and request bodies. Both operations validate first; if parsing fails, your text is left untouched and the error is shown.

Things that change when you reformat

  • Large integers lose precision. JavaScript numbers are 64-bit floats, so integers above 9007199254740991 are rounded. 12345678901234567890 comes back as 12345678901234567000. IDs that large, such as Twitter-style snowflakes, should be strings in the source data.
  • Duplicate keys collapse. If an object repeats a key, only the last value survives.
  • Key order can change. JavaScript puts integer-like keys such as "1" first in ascending order, so {"b":1,"1":2} comes back with "1" first.
  • Number formatting is normalised. 1.50 becomes 1.5 and 1E3 becomes 1000.

If your goal is a different format, use the JSON to YAML converter or JSON to CSV. For a longer walk-through of reading and debugging JSON, see the JSON formatting guide.

Examples

  • ▸ Beautifying an API response for debugging.
  • ▸ Minifying JSON before embedding it in code.

Frequently asked questions

Is my JSON sent to a server?

No. Formatting and validation run entirely in your browser, so sensitive data in your JSON never leaves your device.

Why does my JSON show an error?

Common causes are trailing commas, single quotes instead of double quotes, or missing brackets. The validator points to the position of the problem.

Does JSON allow comments?

No. RFC 8259 has no comment syntax, so // and /* */ make the document invalid. Remove them before validating, or use a superset format such as JSON5 or YAML if you need comments in config files.

Why did my number change from 1.50 to 1.5, or a long ID get altered?

The formatter parses your JSON and rebuilds it, so numbers are normalized. JavaScript also stores numbers as 64-bit floats, so integers above 9007199254740991 lose precision; keep very large IDs as strings in your source data.

What is the difference between beautify and minify?

Beautify adds line breaks and indentation (2 spaces, 4 spaces or tabs) so humans can read the structure. Minify strips all optional whitespace to produce the smallest valid text, which is useful for request bodies and embedded config.

Related guides