Guide
What is JSON?
JSON is the most widely used format for exchanging data on the web. Here’s everything you need to know — from syntax to real-world use.
JSON (JavaScript Object Notation) is a lightweight, text-based format for storing and exchanging structured data. It was popularised by Douglas Crockford in the early 2000s, standardised as RFC 8259 and ECMA-404, and is now the default format for web APIs, configuration files, NoSQL databases and logs.
Although it grew out of JavaScript, JSON is language-independent: every mainstream language can read and write it.
A first example
{
"name": "Ada Lovelace",
"born": 1815,
"mathematician": true,
"languages": ["English", "French"],
"spouse": { "name": "William King", "title": "Earl of Lovelace" },
"website": null
}
This object has six members. Each member is a key (always a double-quoted string) followed by a colon and a value.
The six JSON data types
| Type | Example | Notes |
|---|---|---|
| String | "hello" | Double quotes only; escape \", \\, \n, \uXXXX |
| Number | 42, -3.14, 1e10 | No leading zeros, no NaN or Infinity, no hex |
| Boolean | true, false | Lowercase only |
| Null | null | Lowercase only |
| Object | {"a": 1} | Unordered key/value pairs |
| Array | [1, "two", true] | Ordered list of any values |
Dates, binary data and comments are not part of JSON. Dates are usually written as ISO 8601 strings ("2026-03-14T09:26:53Z") and binary data as Base64 strings.
JSON syntax rules
- Keys must be strings in double quotes:
{"id": 1}, not{id: 1}or{'id': 1}. - No trailing commas:
[1, 2, 3], not[1, 2, 3,]. - No comments. If you need them, consider JSON5 or YAML for config files.
- A document contains exactly one top-level value (usually an object or an array).
- Whitespace between tokens is insignificant — which is why JSON can be minified or pretty-printed freely.
Breaking any of these rules makes the JSON invalid. Paste it into the JSON Validator to see exactly where and why.
JSON vs XML vs YAML
| JSON | XML | YAML | |
|---|---|---|---|
| Readability | Good | Verbose | Excellent |
| Comments | No | Yes | Yes |
| Typical use | APIs, data exchange | Documents, SOAP, enterprise | Config files, CI/CD, Kubernetes |
| Parsing speed | Very fast | Slower | Slower |
You can convert between them with the JSON to XML, XML to JSON and JSON to YAML converters.
Reading and writing JSON in code
// JavaScript
const data = JSON.parse('{"id": 1, "tags": ["a", "b"]}');
const text = JSON.stringify(data, null, 2);
# Python
import json
data = json.loads('{"id": 1}')
text = json.dumps(data, indent=2)
// Go
var order Order
err := json.Unmarshal(bytes, &order)
For typed languages, generate the classes automatically from a sample: TypeScript, Python, Go, Java, C# and 15 more languages.
Common pitfalls
- Big integers: JavaScript numbers lose precision above 253, so 64-bit IDs can be silently rounded. Send them as strings.
- Duplicate keys: allowed by the spec but handled inconsistently — most parsers keep the last value.
- Encoding: JSON must be UTF-8 when exchanged between systems.
- Security: never use
eval()to parse JSON; always useJSON.parseor your language’s parser.
Try it
Paste any JSON into the JSON Formatter to pretty-print, validate and explore it as a tree — everything runs privately in your browser.