Format JSON Online: JSON Formatter & Validator
Format, validate and minify JSON, with clear error messages for invalid input.
Built and tested by Muhammad Irfan Liaqat · Updated
JSON Formatter: key facts
- Formats (pretty-prints) JSON with 2- or 4-space indentation, or minifies it to one line
- Validates strictly: invalid JSON shows the browser's error message instead of output
- Keeps keys in their original order and does not change any values
- Paste-in only; the JSON stays in your browser
How JSON formatting and validation work
Paste JSON into the formatter to re-indent it into readable, nested lines, or minify it into a single compact line. If the input is not valid JSON, you get your browser's parser error instead, which points to the problem, such as a missing comma, an unclosed bracket or a trailing comma.
Formatting normally changes only whitespace; the section below lists the few cases where values or key order change. Choose 2-space or 4-space indentation to match your project's style. Strict JSON is less forgiving than JavaScript: keys and strings need double quotes, trailing commas are not allowed and comments are not part of the format, so an object that works in JavaScript code can still fail here. Parsing happens in your browser, so API responses and config files containing tokens are not sent anywhere.
How to format and validate JSON
- 1Paste or type JSON into the input box
- 2Choose 2 or 4 spaces of indentation
- 3Click Format to beautify the JSON, or Minify to compress it
- 4Fix any error shown, then click Copy to copy the result
Common JSON errors and how to fix them
| Problem | Invalid | Valid |
|---|---|---|
| Trailing comma after the last item | {"a": 1,} | {"a": 1} |
| Single quotes | {'a': 'x'} | {"a": "x"} |
| Key without quotes | {a: 1} | {"a": 1} |
| Comment | {"a": 1 // note} | {"a": 1} |
| JavaScript-only values | {"a": undefined, "b": NaN} | {"a": null, "b": null} |
| Line break or quote inside a string | {"a": "say "hi""} | {"a": "say \"hi\""} |
Browsers word their error messages differently, but most give the position where parsing stopped. The real mistake is usually just before that point.
When formatting changes more than whitespace
The formatter reads your JSON into memory and writes it out again, which is the same thing most programs do with it, so a few details can change. Numbers beyond 9,007,199,254,740,991 lose precision: an ID of 12345678901234567890 comes back as 12345678901234567000. If your data has IDs that large, the API should send them as strings.
Duplicate keys are not an error, but only the last value is kept, so {"a": 1, "a": 2} becomes {"a": 2}. Keys that are whole numbers move to the front in numeric order. Numbers are written in their shortest form, so 1.0 becomes 1 and 1e3 becomes 1000, and escape codes such as \u00e9 are shown as the character é. None of these changes the meaning for a standard JSON parser, but they matter if you compare files line by line.