JSON transmitted over APIs is usually minified (all whitespace removed) to save bandwidth:
{"name":"Alice","age":30,"city":"London","hobbies":["coding","reading"]}
Formatted ("pretty-printed") JSON is far easier to read and debug:
{
"name": "Alice",
"age": 30,
"city": "London",
"hobbies": [
"coding",
"reading"
]
}
Use the tool.tl JSON Formatter:
- Go to tool.tl/json-formatter
- Paste your JSON string into the input box
- Click "Format" โ output appears with syntax highlighting and proper indentation
- Click "Minify" to compress it back to a single line
- Click "Copy" to use the result
Most Common JSON Syntax Errors
JSON has strict syntax rules. Any single error causes complete parse failure. Here are the most frequent mistakes:
1. Single Quotes Instead of Double Quotes
// โ Wrong โ JSON requires double quotes
{'name': 'Alice'}
// โ
Correct
{"name": "Alice"}
2. Trailing Comma
// โ Wrong โ no comma after the last item
{
"name": "Alice",
"age": 30,
}
// โ
Correct
{
"name": "Alice",
"age": 30
}
// โ Wrong โ JSON does not support comments
{
// user data
"name": "Alice"
}
// โ
Use a conventional field instead
{
"_comment": "user data",
"name": "Alice"
}
4. Unescaped Special Characters
// โ Wrong โ backslashes and quotes inside strings must be escaped
{"path": "C:\Users\Alice"}
// โ
Correct
{"path": "C:\\Users\\Alice"}
JSON Data Types Quick Reference
| Type | Example | Notes |
| String | "hello" | Must use double quotes |
| Number | 42 / 3.14 | No quotes |
| Boolean | true / false | Lowercase only |
| Null | null | Lowercase only |
| Array | [1, 2, 3] | Square brackets |
| Object | {"key": "val"} | Keys must be strings |
| Format | Strengths | Best For |
| JSON | Lightweight, human-readable, browser-native | APIs, config files, web data |
| XML | Attributes, namespaces, mature ecosystem | Enterprise systems, SOAP APIs |
| YAML | Comments, less verbose | DevOps config (Docker, K8s) |
| CSV | Simple, Excel-compatible | Tabular data exports |
Frequently Asked Questions
Must JSON keys be strings?
Yes. The JSON spec requires all keys to be double-quoted strings. JavaScript objects allow unquoted keys, but that's not valid JSON โ JSON.parse() will reject it.
Standard JSON does not. If you need comments in a config file, consider JSONC (JSON with Comments, supported by VS Code) or JSON5. Both are supersets of JSON that add comment support.
How do I parse JSON in JavaScript?
Use JSON.parse(jsonString) to convert a JSON string into a JavaScript object. Use JSON.stringify(object, null, 2) to serialize an object to formatted JSON (the 2 sets indentation to 2 spaces).
What does "unexpected token" mean in a JSON error?
It usually means a syntax error at the position indicated โ most often a missing comma, an extra comma, a single quote, or an unescaped character. Paste the JSON into the formatter and it will pinpoint the error location.