JSON Formatter and Validator

Paste your JSON to format it with readable indentation, validate the syntax and find errors with their exact location. It also minifies JSON for production.

JSON Formatter

Malformed JSON is one of the hardest bugs to debug

A misplaced comma, single quotes where double quotes belong, or a field with an undefined value is enough to break an entire application. The trouble is that the parser error often just says "unexpected token" without telling you where the problem is in a JSON document with hundreds of lines.

This formatter parses your JSON, shows the structure with clear indentation and, when there is an error, points to the exact line and column. For production workflows, the minify function strips unnecessary whitespace, shrinking the payload without changing the data.

Syntax rules JSON enforces and JavaScript does not

JSON is a subset of JavaScript, but with stricter rules. All object keys must be strings in double quotes: {"name": "value"} is valid, but {name: "value"} is not. Strings only accept double quotes too; single quotes are invalid. The format does not support comments of any kind, unlike languages such as JavaScript or YAML.

Another critical point is the trailing comma: in JavaScript, [1, 2, 3,] is valid. In JSON, the comma after the last element causes a parse error. Because many developers write JSON with a JavaScript mindset, this is by far the most common source of errors when building payloads by hand.

When to pretty-print and when to minify

Indented JSON (pretty-print) is essential during development: it makes code review easier, it is readable in logs and it makes diffs much clearer. API documentation tools such as Swagger/OpenAPI and Postman display formatted JSON by default for this reason.

In production, minified JSON is the right choice. For high-traffic APIs that return large volumes of data, a 20% to 40% reduction in payload size translates directly into lower bandwidth use and faster responses. Most modern web frameworks minify JSON automatically before sending responses to the client.

JSON in REST APIs: best practices

Well-designed REST APIs use JSON with consistent conventions: camelCase for field names in JavaScript/Node.js APIs, snake_case in Python and Ruby. Dates should follow the ISO 8601 format (e.g. 2024-03-15T10:30:00Z). Monetary values should be represented as strings or integers in cents, never as floats, which can introduce floating-point precision errors.

The Content-Type: application/json header should always accompany requests and responses with a JSON body. Without it, some clients will try to interpret the body as plain text or HTML, causing silent parse failures.

JSON5 and alternatives for configuration files

JSON5 is an extension of JSON that adds features missing from the original, aimed at configuration files written by humans: comments with // and /* */, trailing commas, single-quoted strings and unquoted keys. .eslintrc files and some other config files support JSON5 for exactly this reason.

JSONC (JSON with Comments) is another variant, used by VS Code in its configuration files. For application data exchanged between systems, always use standard JSON for maximum compatibility. Reserve JSON5 and JSONC for configuration files where readability and manual maintenance are the priority.

Frequently asked questions

What is JSON?

JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format. Although the name refers to JavaScript, it is language-independent and natively supported by practically every modern language. It represents data as key-value pairs and ordered lists, which makes it ideal for REST APIs, configuration files and structured data storage.

What are the most common JSON syntax errors?

The most frequent errors are: trailing commas (a comma after the last element of an object or array, valid in JavaScript but invalid in JSON), single quotes instead of double quotes for strings and keys, comments (JSON does not support comments), undefined values (only null is valid), and numbers with leading zeros such as 007. The formatter identifies the exact line and column of the error.

What is the difference between pretty-printed and minified JSON?

Pretty-printed JSON uses indentation and line breaks to make the structure visually readable, which is ideal for debugging, code review and documentation. Minified JSON removes all unnecessary spaces and line breaks, reducing file size. For production APIs, minified JSON saves bandwidth. The difference can be 20% to 40% in size depending on the structure.

Is JSON better than XML?

For modern web APIs, JSON is generally preferable: more concise syntax, native parsing in JavaScript, better integration with NoSQL databases and smaller payloads. XML still has advantages in specific contexts: namespace support, schemas with XSD, transformations with XSLT and legacy systems such as SOAP. The choice depends on the ecosystem and the project requirements.

What is JSON Schema validation?

JSON Schema is a vocabulary that lets you describe the expected structure of a JSON document: field types, required fields, formats, minimum and maximum values. It is different from checking whether the JSON is syntactically correct; the schema validates whether the data is semantically correct for a specific application. Tools such as Ajv (JavaScript) implement validation against schemas.

How do I debug JSON errors in API responses?

Paste the API response into this formatter. If there is a syntax error, the tool will point to the exact line and column of the problem. Common errors in API responses include: error HTML returned with the wrong Content-Type, unescaped control characters in the middle of strings, and responses truncated by a timeout or size limit. Once you find the problem, check the server logs for the original error.