ToolNimbus

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.

Paste your JSON below

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 / MethodHowNotes
VS CodeShift+Alt+F (Win/Linux), Shift+Option+F (macOS), or right-click Format DocumentUses your editor.tabSize and insertSpaces settings; file must be in JSON language mode
Browser DevToolsJSON.stringify(obj, null, 2) in the consolePretty prints any object; useful for inspecting fetched API responses on the fly
Pythonpython -m json.tool file.jsonReads a file or stdin and prints indented JSON; add --indent N to change spacing
jqjq . file.jsonPretty prints by default; jq -c . minifies, and filters can query or transform data
Node.js / JavaScriptJSON.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 JSONPlugin not bundled by default; install it via Plugins Admin first

Frequently Asked Questions

How do I format JSON in VS Code?

Open the JSON file (or set the language mode to JSON), then press Shift+Alt+F on Windows/Linux or Shift+Option+F on macOS. You can also right-click and choose Format Document, or run Format Document from the Command Palette (Ctrl+Shift+P). VS Code applies your configured tab size and space/tab preference.

What is the keyboard shortcut to format JSON?

In VS Code the Format Document shortcut is Shift+Alt+F (Windows/Linux) and Shift+Option+F (macOS). This online tool has no shortcut to memorize, you just paste your JSON and click the Prettify button.

How do I pretty print JSON in JavaScript or the console?

Use JSON.stringify with the third argument set to your indent size, for example JSON.stringify(obj, null, 2) for two-space output or JSON.stringify(obj, null, '\t') for tabs. To minify, call JSON.stringify(obj) with no third argument. This tool calls JSON.parse and JSON.stringify in your browser to do the same thing.

How do I minify JSON?

Paste your JSON and click the Minify button. The tool parses it and re-serializes it with no whitespace, producing a single compact line. Programmatically, the equivalent is JSON.stringify(obj) with no space argument.

How do I convert JSON to a single line?

Click Minify. It collapses your prettified or multi-line JSON into one line, which is ideal for embedding JSON in a query string, an environment variable, a database column, or a code constant where whitespace would be wasted.

Should JSON use 2 spaces, 4 spaces, or tabs?

It is a style choice and does not change the data. Two spaces is the most common convention for JSON on the web and keeps nested data compact; four spaces is easier to scan; tabs let each viewer set their own width. Pick whatever your project or linter expects. This tool lets you choose 2 spaces, 4 spaces, or 1 tab from the Indent dropdown.

Why will my JSON not format?

If you see a red "Invalid JSON" message, the input could not be parsed. The usual culprits are trailing commas, single quotes instead of double quotes, unquoted keys, comments, smart/curly quotes from copy-paste, or extra text after the JSON. The error message includes the parser's reason to help you locate the problem. If the box is empty, the tool just asks you to enter some JSON first.

Is this also a JSON validator?

Formatting requires a successful parse, so a clean result confirms your JSON is structurally valid, and an error message flags that it is not. If you want validation as the primary goal with clearer messaging, use our dedicated JSON Validator tool.

Does this tool show a collapsible JSON tree?

No. It is a formatter and beautifier: it prettifies, minifies, lets you choose indentation, displays parse errors, and copies the output. It does not include a collapsible or interactive JSON tree viewer.

Is my JSON sent to a server?

No. All formatting and minifying happens locally in your browser using the built-in JSON parser, so your data never leaves your device. If you also need to encode or decode data, try our Base64 Encoder / Decoder tool, which likewise runs entirely in the browser.

Related Tools