01 / JSON / json-formatter
JSON Formatter
Format, validate and minify JSON instantly.
How to use
- 01Paste or type JSON into the line-numbered input editor. The footer shows the line count, character count and size as you type.
- 02Press Format, or Ctrl + Enter (Cmd + Enter on a Mac), to pretty-print it with 2-space indentation.
- 03Press Minify to collapse it into a single compact line, or Validate to check the syntax without changing the output.
- 04If the input is invalid, read the error in the input header and fix the line and column it points to.
- 05Explore the result in the Tree view, where you can fold any object or array or use Expand all and Collapse all. Switch to Raw to see the exact text.
- 06Press Copy, or Download JSON to save the result as formatted.json.
What is this tool?
This JSON formatter parses your input with the browser's built-in JSON parser, then re-serializes it either pretty-printed with 2-space indentation or minified onto one line. Because the output is rebuilt from the parsed data, it is always valid JSON. Invalid input is rejected with the parser's error message, and when the browser reports a character position the tool converts it to a line and column so you can jump straight to the problem. The output opens in a collapsible tree that shows how many keys or items a folded node holds, which makes large API responses easy to scan. Everything runs locally in your browser, and your JSON is never uploaded.
Common JSON syntax errors and how to fix them
JSON is stricter than the JavaScript object syntax it resembles, and most errors come from that gap. Trailing commas are the most frequent: {"a": 1,} is fine in JavaScript but rejected here, so delete the comma after the last item in an object or array. Keys and strings must use double quotes, so {'name': 'Ava'} and {name: "Ava"} both fail. Comments of either kind are not allowed, so strip // and /* */ lines from config files before formatting them.
Other common culprits are unescaped characters inside strings, such as a raw line break or a Windows path like C:\temp that needs its backslashes doubled. The values NaN, Infinity and undefined don't exist in JSON either, and True or None from Python output must be written as true and null. When the error points to a line and column, the real mistake is often just before that spot. A missing comma, for example, is only detected when the parser reaches the next key.
What formatting can change besides whitespace
Because the tool parses and re-serializes your JSON rather than re-indenting text, a few details can change, and it helps to know which ones before you paste the result back into a file.
Large integers lose precision. JavaScript numbers are 64-bit floats, so an ID like 12345678901234567890 comes back as 12345678901234567000. If your API sends 64-bit IDs as numbers, compare them as strings instead. Number formatting is normalized too, so 1.0 becomes 1 and 1e3 becomes 1000. If a key appears twice in one object, only the last value survives, and the earlier one disappears without a warning. Keys that look like non-negative integers, such as "2" or "10", are moved to the front of their object in ascending order, while all other keys keep their original order. Unicode escapes like \u00e9 are written out as the character itself.
None of this affects valid data that a typical API consumer would read, but it matters if you diff the output against the original text or rely on key order.
Pretty-print or minify: when to use each
Pretty-printed JSON is for people. Use it when reading an API response, reviewing a fixture in a pull request, or committing a config file, where one value per line produces small, readable diffs. Minified JSON is for machines. Use it when pasting a payload into a curl command, an environment variable or a single-line log field, or when every byte counts.
For example, minifying {"name": "John", "roles": ["qa", "dev"], "active": true} produces {"name":"John","roles":["qa","dev"],"active":true}. The data is identical, only the whitespace is gone. Note that the output panel opens in Tree view, so switch to Raw to see the single minified line. Copy and Download always use the text form, whichever view you have open.
Common use cases
- Reading a minified API response while debugging a failing request
- Pinpointing the line and column of a syntax error in a hand-edited config file
- Validating a request payload before sending it from a test script
- Minifying a JSON body to paste into a curl command or environment variable
- Folding a large nested response in the tree view to find one field quickly
- Normalizing fixture files to 2-space indentation before committing them
FAQ
How do I format JSON online?
Paste your JSON into the input and press Format or Ctrl + Enter (Cmd + Enter on a Mac). The result is pretty-printed with 2-space indentation, and you can copy it or download it as formatted.json.
Why is my JSON invalid?
The most common causes are trailing commas, single-quoted strings or keys, unquoted keys, comments, and unescaped line breaks or backslashes inside strings. The error message shows the line and column when your browser reports a position.
Can I minify JSON?
Yes. Press Minify to remove all whitespace and put the JSON on one line. Switch the output to Raw to see the minified text.
Can I validate JSON without formatting it?
Yes. Press Validate to check the input. The header shows Valid JSON or the error, and the output panel is left unchanged.
Why did a large number change after formatting?
JSON numbers are parsed as JavaScript numbers, which only hold integers exactly up to 9,007,199,254,740,991. Larger integers are rounded, so send big IDs as strings if precision matters.
Does the formatter keep comments or trailing commas?
No. Neither is valid JSON, so input containing them is rejected. Remove them, then format.
Is my JSON uploaded?
No. Parsing and formatting happen entirely in your browser, so it is safe to paste responses that contain internal data.