Guides / JSON
How to Format and Validate JSON
JSON is the most common format for sending data between web apps and APIs. When it breaks, the error message is often hard to read. This guide covers the rules and the fixes.
The basic rules of JSON
JSON is strict. These rules catch most beginners:
- Keys and text values must use double quotes, not single quotes.
- Keys must be quoted strings. Unquoted keys are invalid.
- No trailing commas after the last item in an object or array.
- No comments. JSON does not allow
//or/* */. - Valid values are strings, numbers,
true,false,null, arrays and objects.
Common errors and what they mean
"Unexpected token" or "Expected property name" usually means a missing quote, a stray comma or a bracket that was never closed. Start at the position the error reports and look one or two characters before it. Most of the time the problem is just before that point.
Beautify or minify?
Beautifying adds indentation and line breaks so people can read the structure. Minifying removes all unnecessary whitespace to make the data smaller for transfer. Use beautified JSON while you develop and debug, and minified JSON in production when size matters.
Validate before you send
Validating checks that the text is correct JSON without changing it. It is a quick way to confirm a config file, an API payload or a data export before it causes problems in another system.
Try it yourself
Paste your data into the JSON Formatter to beautify, minify or validate it. Everything runs in your browser, so sensitive API responses are never sent to a server.