.JSON
JavaScript Object Notation
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.
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.
Software
- Visual Studio Code (Windows, macOS, Linux)
- Notepad++ (Windows)
- Sublime Text (Windows, macOS, Linux)
- Firefox, which shows JSON as a browsable tree (Windows, macOS, Linux)
- jq, a command-line JSON processor (Windows, macOS, Linux)
- Python and Node.js, which read and write JSON with no extra libraries
Structure
A JSON file is UTF-8 text holding one value, usually an object or an array. There is no header and no magic number. A value is one of six kinds:
- an object:
{ }around comma-separated"name": valuepairs - an array:
[ ]around comma-separated values - a string: double quotes, with backslash escapes such as
\n,\"andé - a number: decimal, with an optional fraction and exponent
trueorfalsenull
Spaces and line breaks between values carry no meaning. JSON has no comments, no trailing commas and no way to write infinity or NaN. RFC 8259 says a file must not start with a byte order mark, although many readers accept one.