Skip to content

Guide · Developer

How to Format, Validate and Minify JSON

Make unreadable JSON readable, find the exact line that breaks it, sort keys for comparison, and minify it for production, all with a browser-based formatter.

Author
VoltKit
Published
Reading time
2 min read

JSON from an API or a log file usually arrives as a single long line. Formatting it (also called pretty-printing or beautifying) adds indentation and line breaks so the structure is visible. This guide covers formatting, fixing invalid JSON, and minifying it again for production.

Step 1: Paste the JSON

Open the formatter and paste your JSON into the input, or click Paste to read it from the clipboard. The output panel updates as you type; you do not need to press a button.

Do it now withJSON Formatter

Step 2: Fix any errors

If the input is not valid JSON, the message under the editor tells you the line and column, what was found, and the likely fix. Jump to error moves the cursor there. The usual culprits:

  • A trailing comma after the last item ({"a": 1,})
  • Single quotes instead of double quotes
  • Comments, which JSON does not allow
  • undefined, NaN or Infinity, which have no JSON representation

For a deeper look, the JSON Validator shows the error in context with a caret and can remove trailing commas in one click.

Step 3: Choose the layout

  • Indent with 2 spaces (most JavaScript projects), 4 spaces (Python, many APIs) or tabs.
  • Sort keys A–Z to order every object alphabetically. This is useful before comparing two documents, since it removes ordering differences. The JSON Diff tool ignores key order automatically.

Step 4: Copy or download

Use Copy to grab the result, or Download for a .json file. Use output as input feeds the formatted text back into the editor if you want to keep editing.

Minifying for production

Click Minify to remove all whitespace. The result is the same data in the smallest possible form, ideal for embedding in HTML, environment variables or query strings. The size read-out shows how much you saved.

Keyboard shortcuts

  • Ctrl/Cmd + Enter formats
  • Ctrl/Cmd + Shift + M minifies
  • Tab inside the editor inserts two spaces

Next steps

If the JSON comes from an API you are coding against, the JSON to TypeScript tool turns a formatted sample into interfaces. To understand the format itself, read What is JSON?.

Frequently asked questions

Does formatting change the data?

No. Formatting only changes whitespace. Values, key order (unless you enable sorting) and number representation stay the same.

What is the difference between formatting and validating?

Validating checks whether the text is legal JSON and reports where it is not. Formatting takes valid JSON and rewrites it with consistent indentation. The formatter validates as a first step.

Is it safe to paste API responses containing tokens?

The formatter runs in your browser and sends nothing to a server. You can confirm this in the browser's network tab. Even so, treat tokens like passwords.

← Back to Guides

You might also like

Something useful from another corner of VoltKit.