JSON stands for JavaScript Object Notation, a lightweight, text-based format for storing and exchanging data. It is everywhere in modern software: web APIs send responses in JSON, config files use it, and databases store it. Despite the name, JSON is language-independent - almost every programming language can read and write it. This guide explains what JSON is, the six value types it supports, the syntax rules that make a document valid, the most common errors people hit (trailing commas, single quotes, missing commas), and the difference between formatting and minifying so you know when to use each.
What is JSON?
JSON is a plain-text format for representing structured data as a string. Because it is just text, it travels easily over a network and can be saved to a file, logged, or pasted into a chat. It grew out of JavaScript syntax but is now an independent standard that any language can parse, which is why it became the default way for web services to talk to each other. When an app fetches data from an API, what comes back over the wire is almost always a JSON string that the app then parses into objects it can work with. If you ever want to inspect that raw string, paste it into the JSON Formatter to see its structure clearly.
JSON data types
JSON has exactly six value types. Every piece of data in a JSON document is one of these:
- Object: an unordered collection of key/value pairs wrapped in curly braces, for example {"name": "Ada"}. Keys must be double-quoted strings.
- Array: an ordered list of values wrapped in square brackets, for example [1, 2, 3].
- String: text wrapped in double quotes, for example "hello".
- Number: an integer or decimal such as 42 or 3.14. No quotes, and no leading zeros.
- Boolean: the literal true or false (lowercase, unquoted).
- Null: the literal null, used to mean 'no value'.
Note what is missing: there is no date type (dates are usually stored as strings), and the special values undefined, NaN, and Infinity are not valid JSON. Objects and arrays can nest inside each other freely, which is how JSON represents complex, tree-shaped data.
JSON syntax rules
The rules are strict and worth memorising, because most 'broken JSON' comes from breaking one of them:
- Object keys must be strings in double quotes. {"id": 1} is valid; {id: 1} is not.
- Strings use double quotes only. 'single quotes' are not allowed, even though they are fine in JavaScript.
- Commas separate items inside objects and arrays, but there must be no trailing comma after the last item.
- Comments are not allowed - neither // nor /* */.
- Whitespace between tokens (spaces, tabs, newlines) is insignificant and ignored by parsers.
Here is a small valid example that uses every data type:
{"name": "Ada", "age": 36, "active": true, "nickname": null, "skills": ["math", "logic"], "address": {"city": "London"}}
Common JSON errors
Almost every parse failure traces back to a handful of mistakes. The three most frequent are a trailing comma, single quotes, and a missing comma between items:
- Trailing comma: {"a": 1, "b": 2,} - the comma after 2 is invalid. Remove it.
- Single quotes: {'a': 1} - keys and strings must use double quotes, so it becomes {"a": 1}.
- Unquoted keys: {a: 1} - the key needs quotes: {"a": 1}.
- Missing comma: {"a": 1 "b": 2} - there must be a comma between the two pairs.
- Unescaped characters: a double quote or newline inside a string must be escaped as \" or \n. {"text": "she said "hi""} breaks the string and needs {"text": "she said \"hi\""}.
When a parser reports an error, it usually points to a line and column. Start there and check for one of the issues above - a stray comma or the wrong quote character is the culprit far more often than anything exotic. Pasting the text into the JSON Formatter will pinpoint the exact spot where parsing fails.
Formatting vs minifying
Because whitespace is insignificant, you can add or remove it freely without changing the data at all. That gives you two useful operations. Formatting (also called beautifying or pretty-printing) adds indentation and line breaks so the structure is easy to read while you debug. Minifying strips every optional space and newline to make the document as small as possible, which matters when you are sending it over a network or storing it at scale.
For example, the minified value {"a":1,"b":[2,3]} and its formatted version - with each key on its own indented line - are exactly the same data to a parser. Use formatting when a human needs to read it; use minifying when a machine needs to transfer it efficiently.
How to validate and fix JSON
Validating JSON means checking that it follows every syntax rule so a parser will accept it. The practical workflow is straightforward:
- Paste the JSON into a validator or formatter and let it parse the text.
- If it reports an error, jump to the line and column it names.
- Fix the usual suspects: remove trailing commas, replace single quotes with double quotes, quote any bare keys, and add any missing commas.
- Re-run until it parses cleanly, then format it to confirm the structure reads as you expect.
Once your JSON is valid, you can convert it to other formats - for instance turn an array of objects into a spreadsheet with JSON to CSV, or go the other way with CSV to JSON.
Try it yourself
The fastest way to understand JSON is to work with it directly. Paste any snippet into the JSON Formatter to validate it, see exactly where a trailing comma or single quote breaks it, and switch between a readable formatted view and a compact minified one in a click.
Frequently asked questions
- What does JSON stand for?
- JSON stands for JavaScript Object Notation. It is a lightweight, text-based, language-independent format for storing and exchanging data, and it is widely used by web APIs and config files.
- Why is my JSON invalid?
- The most common causes are a trailing comma after the last item, using single quotes instead of double quotes, unquoted object keys, or a missing comma between items. Comments and the values undefined, NaN, and Infinity are also not allowed in JSON.
- What is the difference between formatting and minifying JSON?
- Both only change whitespace, so the underlying data stays identical. Formatting (pretty-printing) adds indentation to make JSON easy to read, while minifying removes all optional whitespace to shrink it for faster transfer or storage.