JSON Formatter & Validator
JSON Formatter indents messy JSON so you can read it, minifies it back to a single line, and validates it — reporting the exact line and position where parsing failed. It is the fastest way to find out why an API response or a config file is being rejected.
Runs entirely in your browser — nothing you enter is uploaded.
DeveloperAbout formatting and validating JSON
Formatting and validating are the same operation: the text has to be parsed before it can be re-printed, so anything that comes back indented is necessarily valid. When it does not, the error names the position where the parser gave up. That position is where the document stopped making sense, which is often just after the real mistake — a missing comma is usually reported at the start of the next line.
Four things trip people up most, and all four are JSON being stricter than
JavaScript. Trailing commas are not allowed. Keys must be double-quoted, so
{name: "Ada"} is invalid. Single quotes are not strings.
And comments do not exist in JSON at all, which is why a config file
copied from documentation with a // note in it will not parse.
Common questions
- What are the most common reasons JSON fails to parse?
- Four, in roughly this order: a trailing comma after the last item in an object or array; keys that are not wrapped in double quotes; single quotes used for strings instead of double quotes; and comments, which JSON does not support at all. JavaScript allows the first three, which is exactly why they are easy to write by accident.
- Why does the error point at a line that looks fine?
- Because the position reported is where the parser could no longer make sense of the document, not necessarily where the mistake is. A missing comma at the end of one line is usually reported at the beginning of the next, since that is where an unexpected token appears. Look at the line before the one named as well.
- What does minifying actually remove?
- Every space and line break outside of string values. It changes nothing about the data — the parsed result is identical — but on a large document it commonly removes twenty to thirty per cent of the bytes, which is worth having on an API response sent thousands of times a day.
- Is my JSON sent anywhere to be validated?
- No. Parsing happens in your browser using the same engine your JavaScript runs on, so nothing is transmitted. That matters for this tool in particular: API responses and configuration files routinely contain keys, tokens and customer records, and pasting them into a service that uploads them is a genuine disclosure.