ToolBook
Support us on Ko-fi
Help us keep this free, forever

JSON Formatter

How to format and validate JSON online

Validate, pretty-print, or minify a JSON document in seconds.

  1. Paste your JSON

    Click the input area and paste the raw JSON text you want to format.

  2. Upload a file (optional)

    Click the Upload button next to the input panel to load a local .json or .txt file directly instead of pasting.

  3. Choose an indent style

    Pick 2 spaces, 4 spaces, tab, or Minify from the toolbar above the output.

  4. Read any errors

    If the JSON is invalid, a red error bar shows the exact line and column and describes what went wrong.

  5. Copy or download

    Click Copy to send the formatted result to your clipboard, or Download to save it as a .json file.

Frequently asked questions

What does the JSON Formatter do?

It parses your JSON text, checks it for syntax errors, and re-serialises it with consistent indentation. You can choose 2 spaces, 4 spaces, a tab, or minify it back to a single line.

Is my JSON data sent to a server?

No. All formatting and validation happens entirely in your browser using the JavaScript engine. Nothing is transmitted or stored anywhere.

What does the error "Unexpected token" mean?

It means the parser hit a character it did not expect at that position. Common causes are trailing commas, missing quotes around keys, or using single quotes instead of double quotes.

What is the difference between pretty-print and minify?

Pretty-print adds whitespace and newlines so humans can read the structure. Minify strips all non-essential whitespace to reduce file size, which is useful before committing to a config file or sending data over a network.

What do the stats (keys, depth, size) mean?

Keys = total number of named properties across all objects. Depth = maximum nesting level. Size shows the original, formatted, and minified byte counts so you can see how much space indentation adds.

Can I format very large JSON files?

The formatter handles megabyte-range JSON comfortably in modern browsers. For files above roughly 5 MB the browser may slow down. In that case a local CLI tool like jq is a better fit.

What is JSON and when do developers use it?

JSON (JavaScript Object Notation) is a lightweight text format for exchanging data between systems. Developers use it for API responses, configuration files, and storing structured data. It is human-readable and supported by every major programming language.

Can I upload a JSON file instead of pasting?

Yes. Click the Upload button in the input panel to load a .json or .txt file from your device. The file contents load directly into the editor so you can format or validate them straight away.

Does this JSON formatter work on mobile?

Yes, the tool works in any modern mobile browser. The layout stacks into a single column on smaller screens. Paste your JSON or upload a file and get the formatted result instantly without installing anything.

Does this work with JSON5 or JSONC files that have comments?

No. This tool validates standard JSON (RFC 8259), which does not allow comments or trailing commas. If your file uses JSON5 or JSONC syntax, strip the comments first before pasting.

JSON formatting: why it matters and how it works

From validation errors to tree views — what every developer should know about working with JSON.

What is JSON and why does formatting matter?

JSON (JavaScript Object Notation) is the de facto interchange format for data on the web. REST APIs return it, configuration files use it, and databases store it. When it arrives minified — as a single dense line — reading it requires a formatter.

A formatter does three things: it validates the syntax, re-serialises the data with consistent indentation, and optionally minifies it back for storage or transmission.

The JSON syntax rules developers most often break

JSON is strict in ways XML and most config formats are not:

  • Keys must be double-quoted strings. {name: "Alice"} is invalid; {"name": "Alice"} is correct.
  • Trailing commas are illegal. [1, 2, 3,] fails. Most linters catch this, but it slips through when hand-editing.
  • Single quotes are not allowed. {'name': 'Alice'} is JavaScript object literal syntax, not JSON.
  • Comments are not part of the spec. If your toolchain uses JSON-with-comments (JSONC), a standard JSON parser will reject the file.
  • Numbers must not have leading zeros. 010 is an error; 10 is fine.

Indentation: 2 spaces, 4 spaces, or tabs?

The choice is stylistic, but conventions vary by ecosystem:

| Format | Common in | |---|---| | 2 spaces | JavaScript/TypeScript projects (npm default) | | 4 spaces | Python (PEP 8 inspired), Java | | Tabs | Go (gofmt), Makefile enthusiasts |

For configuration files committed to a repository, pick whichever matches your .editorconfig or prettier config and never change it — diffs over whitespace-only changes pollute git history.

When to minify

Minified JSON removes all non-essential whitespace. A 100 KB pretty-printed file might become 60 KB minified. The difference matters when:

  • Serving JSON over a slow mobile connection (though gzip compression reduces the gap significantly)
  • Storing JSON in a column-level database field where byte counts are metered
  • Embedding JSON in a <script> tag where file size directly affects page load

For API responses, let your server gzip the response rather than manually minifying — you get the size benefit without losing human-readability in development.

Reading validation errors

A good formatter reports the exact position where parsing failed. Typical messages:

  • "Unexpected token , in JSON" — trailing comma before a closing bracket
  • "Unexpected end of JSON input" — missing closing brace or bracket
  • "Expected property name or '}'" — an extra comma at the end of an object
  • "Unexpected token ' in JSON" — single quotes used instead of double

When you see a line/column number, count from the top-left. Most errors are within 2–3 characters of the reported position.

Understanding the stats: keys, depth, and byte counts

Keys is the total count of named properties across all objects in the document. A deeply nested API response with 50 objects each having 5 keys reports 250.

Depth is the maximum nesting level. {"a": {"b": {"c": 1}}} has a depth of 3. Very deep nesting (10+) is usually a sign of data modelling problems.

Byte counts tell you the cost of formatting. The original bytes count what you pasted. Pretty bytes count the formatted version. Minified bytes show the floor. The gap between pretty and minified is your indentation overhead — for deeply nested structures it can be 30–50%.