Data tools

JSON Formatter

Format, minify and validate JSON in a clean, readable view.

Back to Tooldam

EXAMPLE

Try an example

Load the example, select 2 spaces, turn on Sort object keys, and click Format. Compare the order in the stock object and the priority array.

Product JSON with stock and shipping priority
{"stock":{"west":2,"east":1},"name":"Grid notebook","priority":["west","east"]}

EXAMPLE RESULTS

Product stock JSON formatting results

The table shows results from the sample files and settings. Output and file size can vary with the input and selected options.

Load a sample above to try the same settings yourself.

SampleSettingResultChange / size
Product JSON with stock and shipping priority2-space indentation · sort object keys1 line → 11 lines · 1 line after minifyingstock: east → west · priority: west → east
Browse example files

Guide

Turn hard-to-read JSON into a clear structure

Indent long one-line API responses or configuration data for easier reading, or remove unnecessary whitespace to create compact JSON. Invalid JSON is flagged and an error location is shown when it can be determined.

How to use

  1. Type or paste JSON into the input area.
  2. Choose Format or Minify, and adjust indentation or key sorting when needed.
  3. Review validation and copy the resulting JSON.

What is the difference between formatting and minifying JSON?

Formatting adds line breaks and indentation around objects and arrays so the structure is easier to read. Minifying removes whitespace that is not needed by the JSON syntax, producing a compact one-line representation. The underlying data stays the same.

Should I use 2 or 4 spaces for indentation?

Both produce valid JSON. Two spaces keep the output shorter, while four spaces can make deeply nested structures easier to scan. Use the style that matches your project or preference.

When is sorting object keys useful?

Keeping object keys in a predictable order can make visual comparisons and configuration reviews easier. If an external system relies on the original display order, leave key sorting disabled.

Common JSON syntax errors

  • Strings are not wrapped in double quotes.
  • An object or array has an unnecessary trailing comma.
  • Opening and closing braces or brackets do not match.
  • A colon between a key and value or a comma between items is missing.

What changes, and what stays the same?

Formatting, minifying, or sorting JSON keys changes how the same JSON structure is represented; it does not convert the data into another format. Invalid JSON must be corrected before it can be processed.

How is this different from a similar tool?

Use JSON ↔ CSV when you need a table-oriented conversion. JSON Formatter is for keeping nested JSON structure while making it easier to read or more compact for transport.

What to check if the result is not what you expected

If parsing fails, check trailing commas, quotation marks, matching braces/brackets, and escape characters inside strings. Standard JSON does not accept comments or general JavaScript object syntax.

Practical ways to use this tool

Use it to expand API responses for inspection, review the structure of long configuration JSON, or remove unnecessary whitespace before transport. Sorting keys can also make two JSON objects easier to compare visually.

What to check before you start

Keep an original copy of important configuration files before sorting or minifying. Even valid JSON may still need a particular key convention or value format required by the software that consumes it.

Compare the order of stock keys and shipping priorities

This one-line product JSON has a stock object with quantities by warehouse and a priority array with the shipping order.

  • Load the example and click Format with 2-space indentation. With Sort object keys off, stock appears first, and west comes first within stock.
  • Turn on Sort object keys and click Format again. The result spans 11 lines. The top-level keys read name → priority → stock, and the stock keys read east → west. The priority array still reads west → east.
  • Click Minify with the same setting. The result fits on one line and still shows the product name Grid notebook and quantities of 1 for east and 2 for west.

Try a comma before the closing brace

In the example input, add a comma just before the final } so the text ends in ,}. The tool flags a syntax error and disables Format and Minify. Delete the added comma to make the input valid and enable both buttons again.

FAQ

Frequently asked questions

Does formatting JSON change its values?

Normal formatting parses the JSON and writes it back in a readable layout, so the meaning of the values is preserved. Enabling key sorting can change the displayed order of object keys.

Can minified JSON be formatted again later?

Yes. If the JSON is valid, paste the minified result back into the formatter and format it again.

Does the tool automatically fix invalid JSON?

No. It focuses on validation and error information rather than guessing how invalid data should be changed.

Where is the JSON processed?

Parsing, formatting, minifying and validation are handled in your current browser.