You copy a response from an API, paste it into your code, and get a cryptic message like "Unexpected token } in JSON at position 87." You stare at the screen. The data looks fine. Somewhere in that wall of text there is one missing comma or one stray quote, and finding it by eye can take longer than writing the code around it.
That is exactly the problem a JSON formatter and validator solves. In this guide you will learn what valid JSON looks like, the mistakes that break it most often, and how to fix them quickly with our free JSON Formatter & Validator.
Have messy or broken JSON right now?
Paste it into the tool to make it readable and check whether it is valid. It is free and needs no sign-up.
Open the JSON Formatter & ValidatorWhat Is JSON?
JSON stands for JavaScript Object Notation. It is a lightweight text format for storing and sending data, and it is used almost everywhere: web APIs, app settings, databases and configuration files. Despite the name, you do not need JavaScript to use it. Nearly every programming language can read and write JSON.
JSON is built from just a few pieces: objects in curly braces, arrays in square brackets, and values that can be strings, numbers, true, false or null. Here is a small, valid example:
{
"name": "Asha",
"age": 28,
"skills": ["SEO", "Blogging"],
"available": true
}
What Does a JSON Formatter and Validator Do?
These are two related jobs, and a good tool does both at once.
- Formatting (also called beautifying) adds line breaks and indentation so nested data is easy to read. Data copied from an API often arrives as one long line, which is almost impossible to scan.
- Validating checks the text against the JSON rules and tells you if something is wrong, ideally pointing to where the problem is.
There is also minifying, which does the opposite of formatting. It strips spaces and line breaks to make the data smaller, which is handy when you want to send it over a network.
How to Use Our JSON Formatter & Validator
- Open the JSON Formatter & Validator.
- Paste your JSON into the input box.
- Run the formatter and validator.
- If the JSON is valid, copy the cleaned-up result. If it is not, read the error message, fix the problem and run it again.
The Most Common JSON Errors (and How to Fix Them)
Most invalid JSON comes down to a handful of mistakes. JSON is stricter than JavaScript, so things that look normal to a coder will still fail.
| Mistake | Invalid example | Fix |
|---|---|---|
| Trailing comma | {"a": 1, "b": 2,} | Remove the last comma: {"a": 1, "b": 2} |
| Single quotes | {'name': 'Asha'} | Use double quotes: {"name": "Asha"} |
| Unquoted key | {name: "Asha"} | Put the key in double quotes: {"name": "Asha"} |
| Missing comma | {"a": 1 "b": 2} | Add a comma between items: {"a": 1, "b": 2} |
| Comments | {"a": 1 // note} | Remove the comment. Standard JSON does not allow comments. |
| Wrong values | {"a": undefined} | Use null. JSON has no undefined or NaN. |
| Unescaped line break in a string | A real new line inside quotes | Write it as \n instead. |
| Leading zeros in numbers | {"id": 007} | Write 7 or put it in quotes as text. |
Understanding the error messages
Error wording depends on the tool or programming language, but a few messages appear again and again. "Unexpected token" usually means there is a character where one should not be, such as a trailing comma or a single quote. "Unexpected end of JSON input" often means a closing bracket or brace is missing. When you see either one, look just before the position the message points to, because the real mistake often sits a character or two earlier.
JSON vs a JavaScript Object
This is a common source of confusion. A JavaScript object can have unquoted keys, single-quoted strings, comments around it and trailing commas. JSON allows none of that. If you copy an object out of your JavaScript code and paste it as JSON, it may fail validation even though your code runs fine. Run it through a validator, add the quotes, and it will be ready.
Helpful Habits for Working with JSON
- Format before you debug. Readable, indented data makes mistakes far easier to see.
- Keep key names consistent. Pick one style, such as
camelCaseorsnake_case, and use it everywhere. - Validate before you ship. Check JSON files and API payloads before they reach production.
- Minify only for delivery. Keep the readable version for editing and use the compact version only when size matters.
A Quick Note on Privacy
JSON often contains real information. Before you paste anything into any online tool, remove sensitive data such as passwords, API keys, access tokens and personal details. Replace them with dummy values while you debug the structure. This is a good habit no matter which tool you use.
Frequently Asked Questions
What is the difference between a JSON formatter and a validator?
A formatter makes JSON easier to read by adding indentation and line breaks. A validator checks whether the JSON follows the rules. Many tools, including ours, do both together.
Why does my JSON say "Unexpected token"?
This usually means a character is in the wrong place, such as a trailing comma, a single quote, or a missing comma between items. Check the text just before the reported position.
Can JSON have comments?
No. Standard JSON does not support comments. Some configuration formats allow them, but a strict validator will report them as errors.
Should JSON keys use single or double quotes?
Double quotes only. Single quotes and unquoted keys are not valid in JSON.
What does minifying JSON mean?
Minifying removes extra spaces and line breaks to make the data smaller. The content stays the same, but it becomes harder for people to read.
Final Thoughts
Most JSON problems are small: a stray comma, the wrong kind of quote or a missing bracket. The hard part is spotting them in a block of unformatted text. Format first, validate second, and fix one error at a time. When you are ready to try it, open the free JSON Formatter & Validator, and browse our other free developer and SEO tools while you are here.


