How to Format, Validate and Fix JSON
JSON is everywhere: API responses, configuration files, log entries, browser storage and data exports. Computers handle it easily, but a long minified response on a single line is almost impossible for a person to read, and one misplaced comma can make an entire file invalid. A JSON formatter solves both problems: it makes the structure readable and tells you exactly where an error is.
This guide shows how to format, minify and validate JSON for free, explains the most common syntax errors and how to fix them, and shares a few habits that make working with JSON easier.
What JSON looks like
JSON (JavaScript Object Notation) is built from a few simple pieces:
- Objects in curly braces with key/value pairs, such as {"name": "Ana", "age": 31}.
- Arrays in square brackets, such as [1, 2, 3].
- Values: strings in double quotes, numbers, true, false and null.
Objects and arrays can be nested inside each other to any depth, which is exactly why indentation matters for readability.
How to format JSON online
Our free JSON formatter and validator works in your browser.
- Open the JSON formatter.
- Paste your JSON into the input box – an API response, a config file or a log line.
- Click “Format / Beautify” to pretty-print it with your chosen indentation.
- Use “Validate” to check the syntax; if something is wrong, the error shows the line and column.
- Optionally sort keys alphabetically, or click “Minify” to compress it back to one line, then copy the result.
Formatting vs minifying
Formatted JSON is for people: each key on its own line, nested levels indented by two or four spaces. Minified JSON is for machines: no spaces or line breaks, so it is smaller to store and faster to send. A common workflow is to format JSON while debugging and minify it before embedding it in code or sending it in a request.
Sorting keys is useful when you compare two versions of the same data. After sorting both, paste them into the text diff tool to see exactly what changed.
The most common JSON errors and how to fix them
Trailing commas
{"a": 1, "b": 2,} is invalid because of the comma before the closing brace. JavaScript tolerates it; JSON does not. Remove the last comma.
Single quotes
JSON requires double quotes around strings and keys. {'name': 'Ana'} must become {"name": "Ana"}.
Unquoted keys
{name: "Ana"} is valid JavaScript but not valid JSON. Put the key in double quotes.
Comments
Lines starting with // or blocks wrapped in /* */ are not part of standard JSON. Remove them, or store notes in a regular field such as "_comment".
Missing or extra brackets
When an object or array is not closed, the error often appears at the very end of the file. Formatting the part that does parse helps you see where the nesting went wrong.
Unescaped characters in strings
Double quotes and backslashes inside strings must be escaped as \" and \\. Line breaks inside a string must be written as \n.
Wrong values
Use true, false and null in lowercase. Values such as undefined, NaN or Infinity are not allowed.
Reading error messages
A validator usually reports the first place where the parser got confused. The real mistake is often just before that position – for example, a missing comma at the end of the previous line. Jump to the reported line and column, then look a little earlier.
Tips for working with JSON
- Keep configuration files formatted and committed in a consistent style so code reviews are easier.
- Validate JSON before deploying configuration changes – a single syntax error can stop an app from starting.
- When debugging encoded data, decode it first. Tokens and payloads are often Base64 – use the Base64 decoder – and query strings may need the URL decoder.
- Avoid pasting secrets such as API keys or passwords into tools that upload data. A browser-based formatter keeps the data on your machine.
Formatting JSON in code editors and the command line
Most code editors can format JSON: in VS Code, use “Format Document”. On the command line, python -m json.tool file.json pretty-prints a file, and jq . file.json does the same with color. An online formatter is handiest when you just copied a response from a browser, a log or a chat message and want to read it right away.
Summary
To make JSON readable, paste it into the free JSON formatter and click Format. Use Validate to find the line and column of any error, fix the usual suspects – trailing commas, single quotes, unquoted keys and comments – and minify the result when you are done. Everything runs privately in your browser.
Frequently asked questions
What does formatting JSON do?
It adds line breaks and indentation so nested objects and arrays are easy to read. The data itself does not change.
What is the difference between formatting and minifying?
Formatting (beautifying) makes JSON readable for humans. Minifying removes all unnecessary whitespace to make the file as small as possible for sending over a network.
Why does my JSON say it is invalid?
The most common causes are trailing commas, single quotes instead of double quotes, unquoted keys, comments and missing brackets. The validator shows the line and column of the first error.
Is it safe to paste API responses or config files?
Yes. Our JSON formatter runs in your browser and does not send the data anywhere, but you should still avoid sharing secrets such as API keys with other people.
Can JSON contain comments?
Standard JSON does not allow comments. Some tools accept variants such as JSONC or JSON5, but strict parsers will reject them.