What is JSON?
Short answer
JSON (JavaScript Object Notation) is a lightweight, text-based data format used to store and exchange structured data. It is human-readable, language-independent, and is the most common format for web APIs.
What JSON looks like
JSON represents data as key/value pairs inside objects, and ordered values inside arrays. Despite the name, it is not tied to JavaScript: nearly every language can read and write it.
{
"name": "Ada Lovelace",
"active": true,
"roles": ["author", "mathematician"],
"score": 99.5,
"manager": null
}The data types
- String, written in double quotes
- Number, integer or decimal
- Boolean,
trueorfalse - null, the empty value
- Object, an unordered set of key/value pairs in braces
- Array, an ordered list of values in brackets
Rules people forget
- Keys must be strings wrapped in double quotes. Single quotes are not valid JSON.
- No trailing commas after the last item in an object or array.
- No comments. JSON has no syntax for them.
- The format is strict: a single missing brace or quote makes the whole document invalid.
application/json.Where JSON is used
JSON is the default payload for REST APIs, configuration files, log lines, and data exchange between services. Because it maps cleanly onto objects and arrays, most languages can parse it into native data structures in one call.