← Back

JSON Formatter

Beautify, minify and validate JSON

Input JSON

About JSON Formatter

This tool is for anyone holding a JSON blob that is hard to read or possibly broken: a one-line API response, a clipped log entry, a hand-edited config. It parses the text with the browser's own JSON.parse and, on success, prints it again either as multi-line text indented by 2 spaces or as one compact line. It is a strict validator rather than a forgiving parser. It will not repair anything, and comments, single quotes and trailing commas are all rejected.

How it works

  1. Paste your text into the "Input JSON" box, or click "Upload .json File" at the top right to load a file (it replaces whatever is in the box).
  2. Click "Format" for 2-space indentation or "Minify" for a single line with no extra whitespace.
  3. If the JSON is valid, an "Output" panel appears with a copy button and a "Download" button that saves formatted.json.
  4. If not, a red "Syntax error: " message with the engine's reason appears and the output is cleared. Fix the text and click again.

A concrete run

Format {"id":12345678901234567890,"price":1.50,"n":1e3} and the three lines you get back show id as 12345678901234567000, price as 1.5 and n as 1000. Numbers are parsed into JavaScript doubles and printed again, not copied as text. For an error case, {"a":1,} gave "Expected double-quoted property name in JSON at position 7 (line 1 column 8)" on a Node 22 engine; the exact wording, and whether a line and column appear, depends on your browser version.

Range and known limitations

  • Indentation is fixed at 2 spaces; there is no 4-space or tab option. Minify means no indentation and no line breaks.
  • Integers beyond 2^53 and very long decimals lose precision, as shown above, and 1.50 becomes 1.5 while 1e3 becomes 1000. Check order numbers and snowflake IDs, and store them as strings at the source if exactness matters.
  • Duplicate keys keep only the last value, and integer-like keys such as "1" and "2" are moved to the front of an object, so key order in the output can differ from the input.
  • Error text comes from the browser engine; the tool does not draw line numbers or highlight the fault. Current Chrome and Firefox usually report a position, older browsers may only say Unexpected token.
  • There is no size check, so very large files depend on browser memory. Uploaded files are read as text with no encoding detection.
  • Non-ASCII characters such as Chinese are printed as-is rather than as \u escapes, and escape sequences in the input are decoded to characters.

FAQ: why does JSON with comments fail?

Standard JSON has no comments. Files such as tsconfig.json or VS Code settings are JSONC and often contain them, so strip the comments by hand before pasting.

FAQ: why are single quotes and trailing commas rejected?

JSON requires double quotes for strings and keys and forbids a comma after the last item. {'a':1} and [1,2,] are refused because the tool deliberately mirrors JSON.parse.

FAQ: does formatting change my data?

The structure stays, but numbers may be normalised and key order may shift, as described above. That is fine for readability; to compare against an original byte for byte, use a text diff instead of relying on re-serialised output.

FAQ: do minified and formatted versions mean the same thing?

Yes. They differ only in whitespace and parse into identical data, so minify for sending or storing and format for reading.

Privacy

Parsing and printing happen locally in your browser. Pasted or uploaded content is not sent to a server, and Download builds the file on your device.