JSON Formatter
Paste messy, minified, or escaped JSON and this free JSON formatter instantly turns it into clean, readable, properly indented output. It works like a JSON beautifier in the browser: choose 2 spaces, 4 spaces, or 1 tab from the Indent dropdown, click Prettify, and read your data the way it was meant to be read. Need the opposite? One click on Minify collapses everything to a single line for compact storage or transport. Everything runs in your browser with no upload, no sign-up, and no install.
How to Use
Paste your JSON into the large text area at the top (the placeholder shows the expected shape, like {"key": "value"}). Use the Indent dropdown to pick how the formatted output should look: 2 spaces, 4 spaces, or 1 tab. Click Prettify to parse and reformat the JSON with your chosen indentation, or click Minify to strip all whitespace and produce a single compact line. The result appears in the Output card below, and the copy button in its header puts the whole thing on your clipboard. If you leave the box empty the tool asks you to enter some JSON, and if the text you pasted is not valid JSON it shows a red error message such as "Invalid JSON: Unexpected token..." so you know exactly what to fix.
Why This Tool Is Useful
Raw JSON from an API response, a log line, or a config file is often a single dense string that is almost impossible to read or debug by eye. This tool makes that data human-readable in one click, so you can spot a missing field, trace a nested object, or check a value without squinting. Because formatting also requires successful parsing, a clean result doubles as a quick sanity check that your JSON is structurally valid. The Minify mode is just as useful in reverse, shrinking pretty-printed JSON before pasting it into a code constant, a URL, or a database column where every byte counts. And since it all happens locally in your browser, you can safely format sensitive payloads without sending them to a server.
How to format JSON in VS Code and other editors
The fastest way to pretty print JSON inside Visual Studio Code is the built-in Format Document command. Open a file with a .json extension (or set the language mode to JSON), then press Shift+Alt+F on Windows and Linux, or Shift+Option+F on macOS. You can also right-click and choose Format Document, or open the Command Palette with Ctrl+Shift+P and run Format Document. VS Code uses your editor.tabSize and editor.insertSpaces settings to decide between spaces and tabs.
Most editors and command-line tools have an equivalent. The reference table below collects the exact shortcuts and commands for VS Code, browser DevTools, Python, jq, Node.js, and Notepad++. The catch with all of them is that you need that tool open and configured first, which is exactly the gap this paste-and-go formatter fills.
How to pretty print JSON in JavaScript and the console
JavaScript has JSON formatting built into the language through JSON.stringify. The function takes three arguments: the value, an optional replacer, and an optional space argument. Passing a number or string as the third argument is what produces indented, multi-line output.
To pretty print an object in the browser console or a Node.js script, pass null as the replacer and the indent size as the space argument. To go the other direction and minify, simply omit the space argument entirely.
- Pretty print with 2 spaces: JSON.stringify(obj, null, 2)
- Pretty print with 4 spaces: JSON.stringify(obj, null, 4)
- Pretty print with a real tab character: JSON.stringify(obj, null, '\t')
- Minify to one line: JSON.stringify(obj)
- Parse a JSON string first: JSON.parse(text), then stringify the result
- This tool calls JSON.parse and JSON.stringify under the hood, so the prettify and minify output matches what your own code would produce
Minify JSON online and convert JSON to a single line
Minifying JSON removes every space, tab, and newline that exists only for human readability, leaving the smallest valid representation of the same data. Click the Minify button and your pasted JSON collapses to one line. This is the format you want when embedding JSON in a query string, a single-line environment variable, a database field, or a hard-coded constant where extra whitespace is wasted bytes.
Minified and prettified JSON are semantically identical, they parse into the exact same object, so you can freely round-trip between them. Paste a compact API response, hit Prettify to read it, then Minify it again when you are done.
Paste-and-go formatting versus editor and CLI methods
Editor shortcuts like Shift+Alt+F and command-line tools like jq and python -m json.tool are excellent, but they assume the right tool is already installed, open, and configured. That is friction you do not always want. When a colleague pastes a wall of JSON in chat, when you copy a response out of a browser network tab, or when you are on a machine without your usual setup, opening an editor just to indent some text is overkill.
This formatter is the no-install, zero-setup alternative: paste, click, copy, done. It is the best choice for quick one-off inspection, for sharing readable JSON with someone, or for anyone who does not write code. The editor and CLI methods win when JSON formatting is part of a repeatable workflow such as formatting on save, piping through a build step, or transforming data with jq filters.
- Use this tool for quick, one-off formatting with nothing to install
- Use VS Code Format Document when the JSON already lives in a file you are editing
- Use jq when you also need to filter, query, or transform the data
- Use JSON.stringify in code when formatting must happen programmatically
2 spaces, 4 spaces, or tabs: choosing an indent
The Indent dropdown offers 2 spaces, 4 spaces, or 1 tab, and there is no universally correct answer, it is a style choice. Two spaces is the most common convention for JSON on the web and is the default in many tools and style guides because it keeps deeply nested data from drifting too far to the right. Four spaces is easier to scan at a glance and is popular in environments that already use four-space indentation. The tab option lets each developer set their own visual width.
Whatever you pick only affects how the output looks; the data itself is unchanged. If your project or team has a linter or style config, match whatever it specifies so formatted files stay consistent in version control.
Why your JSON will not format: common errors
If the tool shows a red "Invalid JSON" message instead of formatted output, the text could not be parsed. JSON is stricter than the object syntax many people are used to writing in JavaScript or Python, and a single stray character will stop the whole parse. If the box is empty, the tool simply prompts you to enter some JSON first.
The error message includes the underlying reason from the parser, which usually points you near the problem. Fix the issue and click Prettify again.
- Trailing commas after the last item in an object or array are not allowed
- Keys and string values must use double quotes, never single quotes
- Comments (// or /* */) are not valid in standard JSON
- Unquoted keys, undefined, NaN, and trailing text after the JSON all fail
- Copy-paste often introduces smart/curly quotes, replace them with straight quotes
Format JSON in any tool: commands and shortcuts cheat sheet
| Tool / Method | How | Notes |
|---|---|---|
| VS Code | Shift+Alt+F (Win/Linux), Shift+Option+F (macOS), or right-click Format Document | Uses your editor.tabSize and insertSpaces settings; file must be in JSON language mode |
| Browser DevTools | JSON.stringify(obj, null, 2) in the console | Pretty prints any object; useful for inspecting fetched API responses on the fly |
| Python | python -m json.tool file.json | Reads a file or stdin and prints indented JSON; add --indent N to change spacing |
| jq | jq . file.json | Pretty prints by default; jq -c . minifies, and filters can query or transform data |
| Node.js / JavaScript | JSON.stringify(obj, null, 2) | Pass 4 for four spaces or '\t' for a tab; omit the last argument to minify to a single line |
| Notepad++ | Install the JSON Viewer plugin, then Plugins > JSON Viewer > Format JSON | Plugin not bundled by default; install it via Plugins Admin first |