JSON Basics: How to Read, Format and Fix Errors
JSON is one of the most common ways to store and send data on the web. Apps talk to servers in JSON, configuration files use it and many tools export it. Even if you are not a programmer, you may meet JSON when you work with an API, a spreadsheet export or a website setting. Knowing the basics helps you read it and fix it when it breaks.
What JSON looks like
JSON stores data as pairs of keys and values:
{"name": "Ayesha", "age": 24, "student": true, "courses": ["Maths", "Physics"], "address": {"city": "Lahore"}}
The building blocks
- Object: a set of key-value pairs inside curly braces { }.
- Array: an ordered list inside square brackets [ ].
- String: text in double quotes.
- Number: digits, with an optional decimal point or minus sign.
- Boolean: true or false, in lowercase.
- Null: the word null, meaning "no value".
Syntax rules
- Keys must be strings in double quotes.
- Items are separated by commas, and there is no comma after the last item.
- Strings use double quotes, never single quotes.
- Brackets and braces must match and close properly.
- No comments are allowed in standard JSON.
Why format JSON?
Servers often send JSON in one long line without spaces, called minified JSON. It is efficient for machines but hard for people. Formatting (also called "pretty printing") adds line breaks and indentation, so you can see the structure. Before sending data you may minify it again to save space.
The most common errors
| Problem | Example | Fix |
|---|---|---|
| Trailing comma | ["a", "b",] | Remove the last comma |
| Single quotes | {'name': 'Ali'} | Use double quotes |
| Unquoted key | {name: "Ali"} | Put the key in quotes |
| Missing comma | {"a": 1 "b": 2} | Add a comma between pairs |
| Missing bracket | {"a": [1, 2} | Close the array with ] |
| Comment | // note | Remove comments |
How to debug invalid JSON
- Paste it into a validator and read the error message. It usually points to a line or character position.
- Look at that spot and the line before it. Missing commas and quotes often cause errors on the next line.
- Fix one problem at a time, then validate again.
- If the data came from copying, check for smart quotes, hidden characters or cut-off text.
- When in doubt, compare with a small, known good example.
Smart quotes and copy-paste trouble
Word processors and chat apps sometimes replace straight quotes with curly ones, which are different characters. JSON needs straight quotes ("). If a perfect-looking file fails, this is a common cause.
Keep private data private
JSON can contain passwords, tokens and personal information. Do not paste secrets into websites you do not trust, and remove sensitive values before sharing a sample when asking for help.
Frequently asked questions
Is JSON the same as JavaScript?
It was inspired by JavaScript objects, but it is a separate, stricter data format used by many languages.
Can JSON hold dates?
JSON has no date type, so dates are usually stored as strings, for example "2026-12-03".
Try it yourself
Paste your data into the free JSON Formatter to format, minify or validate it right in your browser.