Introduction
JSON is a text format for structured data, taken from the way JavaScript writes objects and arrays. Douglas Crockford described it in the early 2000s, and it is now standardised as ECMA-404 and RFC 8259. It is the usual format for web APIs and is widely used for settings files and data exchange between programs.
Many other formats are JSON underneath: map data, animations, package manifests,
editor settings, schemas and the configuration files of AI models. Several of them keep
the .json extension, so a file's name does not say which one it is; the
names of the properties inside it usually do. Those on this site are listed below under
Also used for.
A related format, JSON Lines
(.jsonl), stores one JSON value per line so that a large file can be read
or appended a record at a time.
Structure
A JSON file is text holding one value, usually an object or an array. There is no header and no magic number. A value is one of these:
- an object:
{ }around comma-separated"name": valuepairs - an array:
[ ]around comma-separated values, which may be of different kinds - a string: double quotes, with backslash escapes such as
\n,\"and\u00E9 - a number: decimal, with an optional fraction and exponent
trueorfalsenull
{
"name": "Ada",
"born": 1815,
"langs": ["en", "fr"],
"active": false,
"note": null
}
Space, tab, line feed and carriage return between values carry no meaning. The
literal names are lower case only. JSON has no comments, no trailing commas and no way
to write infinity or NaN. .jsonc files and VS Code’s settings use a looser
“JSON with comments”, which is not JSON and is not part of the standard.
RFC 8259 requires UTF-8 for JSON exchanged between systems outside a closed ecosystem. It tells writers not to add a byte order mark to JSON sent over a network, and lets readers ignore one.
The pages in this section give the details:
- Syntax – white space, the structural characters, objects, arrays and literal names
- Strings – what must be escaped, all the escapes, surrogate pairs and how names are compared
- Numbers – the grammar, and what software can actually hold
- Encoding and media type – UTF-8, the byte order mark and the
application/jsonregistration - Reading and writing – what parsers and generators must do, limits, and security
- Versions – RFC 4627, RFC 7158, RFC 7159, RFC 8259 and ECMA-404, and what changed
Also used for
- Browser extension manifest – The JSON manifest of a browser extension: its name, permissions and scripts.
- GeoJSON – Map points, lines and areas with properties, written as JSON.
- Hugging Face model config (config.json) – config.json: a model’s architecture and sizes, read before the weights.
- Hugging Face tokenizer (tokenizer.json) – tokenizer.json: a language model’s vocabulary and tokenising rules.
- JSON Schema – A JSON document that describes and validates other JSON documents.
- Lottie animation – Vector animations as JSON, exported from After Effects and played in apps and web pages.
- Visual Studio Code settings – VS Code’s settings.json: dotted setting IDs in JSON with comments.
- jCal: iCalendar in JSON – iCalendar as JSON: events, to-dos and time zones as nested arrays.
- jCard: vCard in JSON – vCard 4.0 contacts as JSON: names, numbers and addresses as arrays.
- npm package manifest (package.json) – A JavaScript package’s name, version, scripts and dependencies, in JSON.
Links
Software
- Visual Studio Code – free code editor that checks JSON syntax and schemas as you type (Windows, macOS, Linux)
- Notepad++ – free text editor with JSON highlighting (Windows)
- Sublime Text – text editor with JSON highlighting (Windows, macOS, Linux)
- Firefox – web browser that shows JSON as a browsable tree (Windows, macOS, Linux)
- jq – command-line tool that filters and reshapes JSON (Windows, macOS, Linux)
Developers
- json – Python’s built-in JSON module (Python)
- JSON – the object built into JavaScript and Node.js (JavaScript)
- nlohmann/json – JSON for modern C++ (C++)
- Jackson – JSON parser and data binding (Java)
- serde_json – JSON with the Serde framework (Rust)