JSON for Beginners: Syntax, Common Errors and How to Fix Them
If you build websites, call APIs or work with data, you will meet JSON constantly. It is the most common format for sending structured data between systems, and it is friendly enough for humans to read. It is also strict, so a single misplaced comma can break a whole file. This guide covers the basics and the errors that trip people up most.
What is JSON?
JSON stands for JavaScript Object Notation. Despite the name, it is language-independent: Python, PHP, Java, Go and nearly every other language can read and write it. A JSON document is plain text describing data in a structured way.
The building blocks
JSON has just six kinds of value:
- String: text in double quotes, such as
"hello" - Number:
42or3.14, with no quotes - Boolean:
trueorfalse - Null:
null - Object: a collection of key-value pairs in curly braces
- Array: an ordered list in square brackets
Here is a small example combining them:
{
"name": "Ada",
"age": 36,
"active": true,
"languages": ["English", "French"],
"address": { "city": "London", "postcode": null }
}
The syntax rules
- Keys must be strings in double quotes.
- Strings must use double quotes, not single quotes.
- Items are separated by commas, and there must be no trailing comma after the last item.
- Every
{and[must be closed with a matching}or]. - Comments are not allowed.
The five most common JSON errors
| Error | Bad example | Fix |
|---|---|---|
| Trailing comma | {"a": 1,} | {"a": 1} |
| Single quotes | {'a': 1} | {"a": 1} |
| Unquoted key | {a: 1} | {"a": 1} |
| Comment inside JSON | {"a": 1 // note} | Remove the comment |
| Missing closing bracket | {"a": [1, 2} | {"a": [1, 2]} |
How to find and fix errors quickly
Reading a long, minified JSON string by eye is nearly impossible, so use tools:
- Paste it into the JSON Validator. It reports the line where parsing failed. The real mistake is often on the line just before the one reported.
- Use the JSON Formatter to indent it, so the structure is easy to follow.
- If you only need a smaller file for production, the JSON Minifier strips whitespace.
- To explore deeply nested data, the JSON Viewer & Tree Editor lets you expand and collapse branches.
Converting JSON to other formats
JSON often needs to move into a spreadsheet or another system. The JSON to CSV converter turns an array of objects into rows and columns, and CSV to JSON does the reverse. For configuration files, JSON to YAML and YAML to JSON are handy.
JSON versus similar formats
- XML is more verbose but supports attributes and comments.
- YAML is easier to write by hand and supports comments, but is whitespace-sensitive.
- CSV is great for flat tables but cannot represent nested data.
Tips for working with JSON
- Keep key names consistent, for example always camelCase or always snake_case.
- Store dates as ISO 8601 text such as
2026-09-24T10:30:00Z. - Never put secrets such as API keys in JSON that you paste into public tools.
- Large numbers can lose precision in some languages, so send very large IDs as strings.
Summary
JSON is simple: six value types and a handful of strict rules. Most "invalid JSON" errors come from trailing commas, single quotes, unquoted keys or missing brackets. A validator and a formatter will find them in seconds, which leaves you free to focus on what your data actually means.