JSON (JavaScript Object Notation) is the most common way to move structured data between programs. APIs return it, config files use it, databases store it, and almost every language can read and write it. This guide explains exactly what JSON is: the handful of value types it supports, how objects and arrays nest, and the strict syntax rules that cause most of the errors beginners hit.
Want to see it in action while you read? Paste any JSON into the JSON formatter to pretty-print it, or the JSON validator to check it for errors.
What JSON actually is
JSON is a text format for representing data as a combination of a few simple building blocks. It was derived from JavaScript object syntax, but it is language-independent — the format is defined by RFC 8259 and the ECMA-404 standard, and parsers exist for every mainstream language. A JSON document is just a string; your program parses that string into native data structures (objects, arrays, numbers) and serialises them back to a string to send or store.
The six JSON value types
Every value in JSON is one of exactly six types — four primitives and two structures:
| Type | Example | Notes |
|---|---|---|
| String | "hello" | Always double quotes. Use \", \\, \n etc. to escape. |
| Number | 42, -3.14, 2.5e8 | One numeric type — no separate int/float, no NaN or Infinity. |
| Boolean | true, false | Lowercase only. |
| Null | null | Lowercase only — represents "no value". |
| Object | {"id": 1} | An unordered set of "key": value pairs. |
| Array | [1, 2, 3] | An ordered list of values of any type. |
Notice what is missing: there is no date type, no comment syntax, and no way to reference another part of the document. Dates are usually written as strings (ISO 8601, e.g. "2026-11-20T09:00:00Z"), and the receiving code is responsible for parsing them.
Objects
An object is wrapped in curly braces and holds "key": value pairs separated by commas. Keys are always strings in double quotes; values can be any of the six types, including more objects and arrays:
{
"id": 42,
"name": "Ada Lovelace",
"active": true,
"roles": ["admin", "author"],
"profile": {
"city": "London",
"joined": "2026-01-15"
},
"deletedAt": null
}
Objects are unordered — {"a":1,"b":2} and {"b":2,"a":1} are equivalent — and keys should be unique. To explore a large object visually, open it in the JSON tree viewer, which collapses and expands nested nodes.
Arrays
An array is wrapped in square brackets and holds an ordered list of values. Unlike objects, order matters and there are no keys:
["red", "green", "blue"]
[
{"sku": "A1", "qty": 2},
{"sku": "B7", "qty": 1}
]
JSON allows arrays of mixed types ([1, "two", true, null]), but most APIs keep arrays homogeneous — a list of objects with the same shape — because that maps cleanly onto tables and typed models.
The syntax rules that cause most errors
JSON is deliberately strict. Five rules account for the vast majority of "invalid JSON" errors:
- Double quotes only.
'single'quotes are invalid, and keys must be quoted —{name: "x"}is a JavaScript object literal, not JSON. - No trailing commas.
[1, 2, 3,]and{"a": 1,}are both errors. - No comments.
// like thisor/* this */will fail. (If you need comments, see JSON5/JSONC below.) - Lowercase keywords.
True,FALSEandNULLare invalid — they must betrue,false,null. - No leading zeros or hex.
007and0xFFare not valid numbers.
When a parser rejects your data, paste it into the validator — it reports the exact line and column of the first error. If the document is broken by a stray comma or quote, the JSON fixer can often repair it automatically. For a deeper walkthrough of specific error messages, see our guide on how to debug invalid JSON.
Escaping characters inside strings
Because strings are delimited by double quotes, any double quote inside a string must be escaped with a backslash, along with a few other characters. The escape sequences are:
\"— a double quote\\— a backslash\/— a forward slash (optional, but allowed)\n,\t,\r— newline, tab, carriage return\uXXXX— any Unicode character by its four-digit hex code point
So a Windows path and a quoted phrase look like this: {"path": "C:\\Users\\ada", "quote": "she said \"hi\""}. Forgetting to escape a backslash in a path is a classic source of “invalid JSON” errors. If you are embedding a chunk of JSON inside another JSON string, the JSON escape tool does the nested escaping for you.
Numbers, precision and big integers
JSON has a single number type and does not distinguish integers from floats. Two things to watch: JSON cannot represent NaN or Infinity (serialisers usually emit null or throw), and very large integers can lose precision because many parsers read numbers as 64-bit floats. If you need exact large IDs (for example a 19-digit database key or a blockchain value), send them as strings rather than numbers so no digits are rounded away.
How JSON is used
- APIs send and receive JSON request/response bodies (with the
application/jsoncontent type). - Config files such as
package.jsonandtsconfig.jsonare JSON. - Databases — document stores like MongoDB, and JSON columns in PostgreSQL/MySQL — store JSON directly.
- Logs and messaging often use JSON (or newline-delimited JSON) so each record is machine-readable.
JSON vs other formats
JSON is not the only option. YAML and TOML are common for human-edited config because they allow comments and are less punctuation-heavy; XML is still used in older enterprise systems. We compare the trade-offs in JSON vs YAML vs TOML. If you need JSON with comments and trailing commas for your own config files, JSON5 is a superset that adds exactly that — strict JSON stays the right choice for data on the wire.
Reading and editing JSON by hand
Minified JSON arrives as one long line, which is unreadable. Run it through the formatter to indent it, or edit it safely in the JSON editor, which highlights syntax and flags mistakes as you type. Everything runs in your browser, so the data never leaves your device.
Key takeaways
- JSON values are one of six types: string, number, boolean, null, object, array.
- Objects are unordered key/value maps; arrays are ordered lists.
- Use double quotes, no trailing commas, no comments, and lowercase
true/false/null. - There is no date type — dates are strings your code parses.
- When in doubt, validate and format before you ship.