JSON Formatter

Pretty-print or minify JSON with 2 spaces, 4 spaces or tabs, sort keys, and see exact error positions.

  • Runs in your browser
  • Free, no sign-up

122 B. Files up to 5 MB are read locally.

Output

Runs entirely in your browser. Nothing you enter is sent to our server.

Formatted JSON

Valid JSON. 8 keys, 2 objects, 1 arrays, depth 2. Output 175 B.

How to use the json formatter

  1. Paste JSON into the input box, or open a .json file up to 5 MB. The file is read locally.
  2. Choose the output style: 2 spaces, 4 spaces, tabs, or minified on one line.
  3. Turn on "Sort keys A to Z" if you want object keys ordered alphabetically at every level.
  4. If the JSON is invalid, read the error message with its line, column and a caret pointing at the problem.
  5. Copy the result or download it as a .json file.

Worked example

Sorting and indenting a small object

Input {"b":1,"a":[1,2]} with 2 spaces and sort keys on becomes { "a": [1, 2], "b": 1 } spread over 7 lines, with "a" first. Input {"a":} is rejected with the error at line 1, column 6, where a value was expected.

How it works

The text is first checked by a strict RFC 8259 parser written for this tool, which reports the exact offset of the first error and converts it to a line and column. Valid input is then parsed with JSON.parse and printed with JSON.stringify using your indent. Key sorting rebuilds each object with keys in code-point order.

Assumptions

  • Input is standard JSON. Comments, trailing commas, single quotes and unquoted keys (JSON5 or JavaScript object syntax) are reported as errors.

Frequently asked questions

Is my data uploaded?

No. This tool runs entirely in your browser. Your input is processed on your device and is not sent to our server or stored.

Why did a large number change after formatting?

JavaScript stores numbers as 64-bit floating point, so integers above 9,007,199,254,740,991 are rounded. The tool warns you when this happens. Keep large IDs as strings in your JSON.

What happens to duplicate keys?

JSON.parse keeps only the last value for a repeated key, so the formatted output contains one copy. The tool warns you and shows the first duplicate. Use the JSON Validator for a full list.

Does it support JSON with comments?

No. Comments are not part of JSON, and the error message tells you where the first comment is. Remove comments before formatting.

Limitations

  • Numbers are normalised by JavaScript (for example 1.0 becomes 1 and 1e2 becomes 100).
  • Keys that look like integers (such as "10") are placed before other keys by JavaScript, even without sorting.
  • Very large files (several MB) can take a moment to format on slower phones.