JSON Formatter: Pretty-Print or Minify with One Click
You got a JSON response from an API and it's a 500-character single line. Or your config file uses tabs but your project uses 2-space indentation. Or you need to minify a JSON payload to paste into a cURL command.
This tool formats JSON with configurable indentation — 2 spaces, 4 spaces, or tabs. It can also keep or remove exact key names at any depth before producing output. It validates on the fly and shows parse errors with line numbers. Or it minifies valid JSON into the most compact form possible.
Runs in your browser. Nothing leaves your machine.
What's actually happening
Under the hood, it's JSON.parse() followed by JSON.stringify() with an indentation argument. Simple and bulletproof — the same JSON engine your browser uses for every API call.
Formatting parses the input to validate it, then re-serializes with your chosen indentation. JSON.stringify(parsed, null, 2) for 2-space, JSON.stringify(parsed, null, 4) for 4-space, JSON.stringify(parsed, null, '\t') for tabs.
Minification is JSON.stringify(parsed) with no indentation argument — produces the most compact valid JSON possible. All whitespace between tokens is removed.
Key filtering parses the input, lists the discovered object keys, applies the selected key filter, then serializes the filtered value. Keep mode preserves matching keys and the parent arrays or objects needed to reach them. Remove mode strips matching keys wherever they appear.
If the input isn't valid JSON, the tool shows the parse error with details about where parsing failed.
Using it
Paste your JSON. Pick your indentation style. Optionally select discovered keys like id, name, or email and choose whether to keep or remove them. Hit Format for pretty-printed output or Minify for compact output. Copy the result.
When you'd actually reach for this
- You're debugging an API response and the JSON is a single unreadable line
- You need to switch indentation style — 2-space for frontend, 4-space for Python, tabs for Go
- You're minifying JSON for a cURL command or environment variable where whitespace wastes space
- You're reducing a large API response to only the keys you need to inspect
- You're removing noisy or sensitive fields before sharing an example payload
- You're cleaning up a hand-edited JSON config file that has inconsistent formatting
- You're copying JSON between tools and want consistent formatting
JSON Formatter vs JSON Validator — what's the difference?
Both tools validate JSON. The difference is intent.
The JSON Validator is focused on validation — "is this valid JSON?" It pretty-prints as a convenience, but the primary output is a pass/fail verdict with error details.
The JSON Formatter is focused on formatting — "make this JSON look right." It validates as a necessity (you can't format invalid JSON), but the primary output is a cleanly formatted string with your preferred indentation.
Use the Validator when you're debugging syntax errors. Use the Formatter when you know the JSON is valid and just want it to look better.
Indentation wars: 2-space vs 4-space vs tabs
2-space — the JavaScript ecosystem default. Most npm packages, most frontend config files, most Node.js projects. If you're working in JS/TS, this is probably what your .prettierrc specifies.
4-space — common in Python, Java, and C#. More visual breathing room, which some developers prefer for deeply nested structures. package.json uses 2, but settings.json in VSCode uses 4. Consistency within a project matters more than the choice itself.
Tabs — the accessibility argument is real: developers with visual impairments can set their tab width to whatever's comfortable. Go uses tabs by convention. In JSON specifically, tabs are less common, but they work fine.
Pick whatever your project uses and stop thinking about it.
Edge cases
Numbers — JSON preserves numeric precision up to IEEE 754 double-precision limits. Numbers larger than Number.MAX_SAFE_INTEGER (9,007,199,254,740,991) will lose precision when parsed. If your JSON has large IDs (like Twitter snowflake IDs), they'll get rounded. This is a JavaScript limitation, not a tool limitation.
Key order — JSON.stringify() preserves insertion order of object keys. Formatting won't alphabetize your keys. If you need sorted keys, that's a separate transformation.
Key filtering — filters match exact key names, not JSONPath expressions. id matches every id key at any depth. user.id only matches a literal key named user.id.
Unicode — JSON supports Unicode natively. Characters like é, 日本語, and emoji serialize correctly. The formatter won't escape them unless they were escaped in the input.
Trailing commas — not valid in JSON. {"a": 1, "b": 2,} will throw a parse error. This trips up developers coming from JavaScript, where trailing commas are allowed.
Troubleshooting
Parse error on what looks like valid JSON — common culprits: trailing commas, single quotes instead of double quotes, unquoted keys, comments (// or /* */), and undefined values. All of these are valid in JavaScript objects but invalid in JSON.
My large numbers changed after formatting — JavaScript parsed them and lost precision. A 64-bit integer ID like 9007199254740993 becomes 9007199254740992. If precision matters, keep those values as strings in your JSON.
The output has \n and \t in strings — those are literal escape sequences in the JSON string values. The formatter doesn't modify string contents, only the structural whitespace between tokens.
Formatting doesn't change anything — your JSON is already formatted with the selected indentation. Try switching to a different indentation style or minifying to see the difference.
The key list is empty — check that the input is valid JSON and contains object keys. Arrays of objects work; arrays of primitives like [1, 2, 3] do not expose keys.
I pasted JSONL (JSON Lines) and it failed — JSONL is multiple JSON objects separated by newlines, not a single JSON document. Each line is valid JSON individually, but the whole thing isn't. Parse each line separately.
What to do with it
Copy the formatted JSON into your code editor, API client, config file, or wherever it needs to go. For programmatic formatting, every language has JSON serialization with indentation options — you don't need a library for this. But for quick one-off formatting, this is faster than opening a REPL.