JSON
JavaScript Object Notation
- Pronunciation
- JAY-sun
In short
JSON is a lightweight, text-based format for storing and exchanging structured data as key-value pairs and lists, readable by both humans and machines.
What is JSON?
JSON is a simple way to write structured data as plain text. It uses curly braces for objects made of key-value pairs, square brackets for ordered lists called arrays, and a small set of value types: strings, numbers, booleans (true or false), null, objects, and arrays.
Although its syntax comes from JavaScript, JSON is language-independent, and almost every programming language can read and write it. Converting data into JSON text is called serialization, and turning JSON text back into data structures is called parsing; in JavaScript these are done with JSON.stringify() and JSON.parse().
JSON is the default data format for most web APIs, and it is also used for configuration files such as package.json, for logs, and for storing documents in NoSQL databases. Its popularity comes from being compact, easy for people to read, and easy for machines to process.
JSON is often confused with JavaScript objects, but it is stricter: keys must be in double quotes, strings cannot use single quotes, and comments, trailing commas, functions, and undefined are not allowed. Compared with XML, JSON is shorter and maps more directly to objects and arrays in code.
At a glance
Key takeaways
- JSON stands for JavaScript Object Notation but works with almost every language.
- Data is written as objects (
{}), arrays ([]), strings, numbers, booleans, andnull. - Keys and strings must use double quotes.
- Standard JSON does not allow comments or trailing commas.
- It is the most common data format for web APIs.
Example
{
"id": 42,
"name": "Ada Lovelace",
"email": "ada@example.com",
"isAdmin": false,
"roles": ["editor", "author"],
"address": {
"city": "London",
"country": "UK"
},
"lastLogin": null
}Readers ask
What is the difference between JSON and a JavaScript object?
A JavaScript object is a value in a running program, while JSON is a text format for representing data. JSON is also stricter: keys need double quotes, and functions, comments, and undefined are not allowed.
Can JSON have comments?
No. Standard JSON does not support comments, although some tools accept variants such as JSONC or JSON5 for configuration files.
What is the difference between JSON and XML?
Both are text formats for structured data. JSON is shorter and maps directly to objects and arrays in code, while XML uses opening and closing tags and is more common in older enterprise systems and document formats.
Often compared
See also
- APIBackend & APIs, p. 2An API is a set of rules that lets one piece of software request data or actions from another in a predictable, documented way.
- REST APIBackend & APIs, p. 38A REST API is a web API that exposes data as resources identified by URLs and lets clients read or change them using standard HTTP methods.
- JavaScriptWeb Development, p. 24JavaScript is the programming language that runs in web browsers to make pages interactive, and it also runs on servers through runtimes like Node.js.
- NoSQLDatabases, p. 29NoSQL is a family of databases that store data in models other than relational tables, such as documents, key-value pairs, wide columns, or graphs.
- HTTPWeb Development, p. 19HTTP is the protocol that browsers, apps, and servers use to exchange web pages and data through a simple cycle of requests and responses.
- XMLBackend & APIs, p. 48XML (Extensible Markup Language) is a text format for structured data that uses nested tags you define yourself, readable by both people and machines.
Sources
Spotted a mistake or something missing on this page?Suggest an edit