JSON: how to format it and fix the most common errors

Learn how to format JSON for readability, read error messages and fix the most common problems, such as trailing commas, single quotes and comments.

You open an API response and find a single line with hundreds of characters and no room to breathe. The JSON is valid, but reading that wall of text to find one field is almost impossible. Formatting solves the reading problem; validating solves the rest — and the two go together.

This guide explains why JSON usually arrives minified, the difference between formatting and minifying, the rules that cause the most errors, and how to use the validator's message to fix the problem. To paste and test right now, use the JSON formatter, which validates and organizes the content in your browser. If your goal is to check whether a JSON document is correct — including against a schema — see also how to validate JSON.

What JSON is and why it arrives minified

JSON (JavaScript Object Notation) is a text format for representing data as key-value pairs. It is the common language between APIs, configuration files and web applications: an object starts with {, a list with [, and values can be strings, numbers, booleans, null, objects or arrays.

Servers usually send minified JSON because every space and line break costs bytes. On an API handling thousands of requests per minute, that adds up. The problem is that the machine-friendly format is hostile to anyone who needs to debug it.

Formatting vs. minifying: when to use each

OperationWhat it doesBest use
FormatAdds indentation and line breaksReading, reviewing, debugging and documenting
MinifyRemoves unnecessary spacesShipping to production, reducing size

Formatting does not change the data: the content stays the same, just organized. Minifying does not change the structure either, but it removes readability. The ideal is to keep the formatted version in development and the minified one in production.

The rules that cause the most errors

These mistakes are common because JavaScript accepts many of these constructs. A hand-written object literal can work in code and fail when sent as JSON — they look alike, but follow different rules.

How to read the error message

When the JSON is invalid, the validator points to a position or a problematic passage. The message usually names the unexpected character, such as “unexpected token” or “expected double-quoted property name”. The fastest path is to go to the indicated position and look at what comes just before it: most of the time, the real error is a few characters to the left.

A trailing comma, for example, is often reported at the closing brace rather than at the comma itself. A single quote shows up as “unexpected token” at the start of the key. If the error makes no sense, format the JSON in stages or reduce the content until you isolate the problematic block.

A workflow for debugging JSON

  1. Paste the content into the validator and see whether it is accepted.
  2. If there is an error, fix one problem at a time and validate again.
  3. Once the JSON is valid, choose the indentation (2 spaces, 4 spaces or tab).
  4. Check the structure: arrays, nested objects and value types.
  5. Copy or download the formatted version for your code or documentation.

This short cycle avoids the classic “I fixed one comma and another error appeared”: each validation confirms that the previous problem is really gone.

Privacy: where the JSON is processed

API responses can contain tokens, emails, customer data and internal information. Prefer tools that process the content locally in the browser, without sending the text to a server. Even then, avoid pasting unnecessary secrets: use sample data when the goal is only to test syntax.

Format and validate your JSON now

In the JSON formatter, paste the content, choose the indentation and see the result and validation message instantly. You can copy it, download the formatted file, or clear everything and start over — no sign-up and no data sent outside your browser.