Developer Tools

JSON Formatter

Live

Pretty-print or compact JSON in a side-by-side formatter with precise syntax feedback.

About JSON Formatter

Paste minified or hard-to-read JSON into the input pane and create clean output with two-space or four-space indentation. Choose Compact to remove insignificant whitespace, copy the finished result, or load a sample to see the expected syntax. Invalid input stays visible while the status panel reports the parser message and, when available, its line and column. Formatting runs entirely in the browser.

Set up JSON Formatter

Workspace

Source workbench

Edit the source fields below and inspect the rendered output alongside your work.

Complete the fields to prepare a result.

Paste valid JSON text. Use double-quoted property names and string values.

Enter the number of spaces to use for each JSON nesting level.

JSON Formatter: formatted json

Choose the values that apply, then format.

Calculation method

Parse with JSON.parse and serialize with JSON.stringify using 0, 2, or 4 indentation spaces.

How it works

The formatter first parses the input as standard JSON, then serializes the resulting value with the chosen indentation. Two or four spaces create pretty-printed output; Compact uses no indentation. Parsing before serialization verifies syntax and normalizes whitespace without changing values or array order.

Practical guide

Beautify JSON for review while validating that the input follows the JSON grammar.

JSON Formatter worked example

The page’s example models formatting a nested API payload for debugging. Change one assumption at a time so the effect on formatted json and valid remains easy to explain.

Treat the displayed formatted json and valid as the result of the example inputs, not as a default recommendation for a different situation.

Assumptions

  • The entered json describe the same scenario and use the units shown beside each field.
  • The calculation applies the stated method consistently and rounds only for display unless the tool says otherwise.

Limitations

  • The formatter first parses the input as standard JSON, then serializes the resulting value with the chosen indentation. Two or four spaces create pretty-printed output; Compact uses no indentation. Parsing before serialization verifies syntax and normalizes whitespace without changing values or array order.
  • The result covers the inputs exposed by this tool; omitted context can change a real-world answer.

Common mistakes

  • expecting a formatter to repair invalid syntax or preserve insignificant whitespace.
  • Changing json without checking the other assumptions can make the comparison misleading.
When to use JSON Formatter
Approach Best for Trade-off
JSON Formatter A transparent calculation that reports formatted json and valid. Accuracy depends on the entered assumptions and the documented method.
a JSON validator or schema validator when conformance is the main question Situations that need different inputs, verification, or broader context. May take longer, cost more, or produce a result that is not directly comparable.

Examples

JSON Formatter: Format sample

Example input
{
    "json": "{\"a\":1}",
    "indent": 2
}
Expected result
{
    "json": "{\n  \"a\": 1\n}",
    "valid": true
}

Privacy

This tool does not store your inputs or results on UtilityPages.org.

Citations & sources

  1. RFC 8259: The JavaScript Object Notation Data Interchange Format

Frequently asked questions

Does formatting change JSON values?

Formatting changes whitespace only. Strings, numbers, booleans, null values, object members, and array order remain the same after parsing and serialization.

Should I use two spaces or four spaces?

Both are valid. Two spaces creates a smaller, commonly used output; four spaces can be easier to scan. Follow the convention of the project receiving the JSON.

What does Compact do?

Compact serializes the parsed value without indentation or line breaks, reducing unnecessary whitespace for transport or storage. It is also commonly called JSON minification.

Why can valid-looking JavaScript fail as JSON?

JSON is stricter than JavaScript object syntax: property names and strings need double quotes, comments are not allowed, and trailing commas, NaN, Infinity, and undefined are invalid.