What is JSON? Syntax, data types and common mistakes explained
JSON explained in plain language: syntax, the six data types, why APIs use it, the mistakes that break it, and how to read and validate JSON quickly.
JSON (JavaScript Object Notation) is a simple text format for structured data. It is how most web APIs send and receive information, how many applications store settings, and how browsers and servers exchange data behind almost every modern website. If you have ever opened a file full of curly braces and quotes, you have seen JSON.
This guide explains the syntax, the data types, the mistakes that break JSON most often, and how to read and validate it without special tools.
What JSON looks like
{
"name": "Versuss",
"articles": 46,
"bilingual": true,
"languages": ["en", "uk"],
"owner": { "country": "UA", "email": null }
}
This is one object with five keys. Each key is a string in double quotes, followed by a colon and a value. Pairs are separated by commas, and the whole object is wrapped in curly braces.
The six data types
- String – text in double quotes:
"hello". Special characters are escaped with a backslash:"line one\nline two","a \"quoted\" word". - Number – integers or decimals, optionally with an exponent:
42,-3.5,1e6. No quotes, no leading zeros, noNaNorInfinity. - Boolean –
trueorfalse, lowercase. - Null –
null, meaning “no value”. - Array – an ordered list in square brackets:
[1, 2, 3]or["en", "uk"]. Items can be of any type, including other arrays and objects. - Object – an unordered set of key/value pairs in curly braces.
That is the whole language. There are no dates, no comments and no functions. Dates are usually sent as strings in ISO 8601 format, such as "2026-10-19T14:30:00Z", or as Unix timestamps.
Why JSON became the default
- Readable by people and easy to generate and parse by programs.
- Supported everywhere: every major programming language has a built-in or standard JSON library.
- Compact compared with XML, which needs opening and closing tags for every value.
- Maps naturally to the objects, lists and dictionaries programmers already use.
In an API request you will usually see the header Content-Type: application/json, which tells the server how to read the body. See what a REST API is and REST API methods for how JSON travels in real requests.
The mistakes that break JSON most often
- Trailing commas.
[1, 2, 3,]and{"a": 1,}are invalid, even though JavaScript accepts them. - Single quotes.
{'name': 'x'}is not JSON. Keys and strings need double quotes. - Unquoted keys.
{name: "x"}works in JavaScript but not in JSON. - Comments.
//and/* */are not allowed. Some tools accept “JSON with comments” (JSONC) for configuration files, but standard parsers reject it. - Unescaped characters. A raw line break or an unescaped double quote inside a string ends it early.
- Wrong encoding or invisible characters. JSON should be UTF-8. A byte order mark or “smart quotes” copied from a word processor can break parsing.
- Huge numbers. JavaScript stores numbers as 64-bit floating point, so integers above about 9 quadrillion lose precision. APIs often send large IDs as strings for this reason.
Reading and validating JSON
Most browsers display JSON responses in a readable, collapsible view when you open an API URL directly. In the browser console you can check a string quickly:
JSON.parse('{"ok": true}') // { ok: true }
JSON.parse("{'ok': true}") // SyntaxError
JSON.stringify({ a: 1 }, null, 2) // pretty-printed text
In a terminal, jq formats and queries JSON, and Python is available on most systems:
curl -s https://api.example.com/items | jq '.[0].name'
python3 -m json.tool data.json
If a parser reports an error “at position 153”, look a few characters before that point: a missing comma or quote earlier in the text is usually the real cause.
JSON Schema: describing what valid data looks like
Syntax alone does not say whether data makes sense. JSON Schema is a separate standard that describes the expected structure, for example that email must be a string in email format and age a number of at least zero. APIs use schemas to validate requests and generate documentation; an OpenAPI description of an API is built on the same idea.
JSON compared with other formats
- XML – more verbose, supports attributes and namespaces, still common in older enterprise systems, RSS feeds and office documents.
- YAML – easier to write by hand and supports comments, popular for configuration such as Docker Compose and CI pipelines. Indentation mistakes are a frequent source of bugs. Valid JSON is also valid YAML.
- CSV – best for flat tables; cannot express nesting.
- Binary formats such as Protocol Buffers or MessagePack – smaller and faster, but not human-readable; common in high-traffic internal services and gRPC.
Security notes
- Never turn JSON into code with
eval(); always use a real parser such asJSON.parse. - Validate incoming JSON before using it. A well-formed document can still contain unexpected types, huge strings or deeply nested structures designed to exhaust memory.
- Do not put secrets such as API keys or passwords in JSON files that are committed to a repository or served publicly.
Key takeaways
- JSON has six types: string, number, boolean, null, array and object.
- Keys and strings use double quotes; no trailing commas and no comments.
- It is the standard body format for web APIs, marked with
Content-Type: application/json. - Use a real parser, validate input, and use tools such as
jqto read it quickly.
Related reading: what an API is, what a webhook is and why file formats matter.