What is JSON? (JavaScript Object Notation)
A definitive guide to JSON, the universal language of modern web APIs, how it works, and why it replaced XML.
The Standard Standard for Data Exchange
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format that is easy for humans to read and write, and extremely easy for machines to parse and generate. Based on a subset of the JavaScript programming language, JSON has completely taken over the internet as the de-facto standard for formatting data sent between clients (like web browsers) and servers in REST APIs.
Understanding JSON Syntax
JSON is built on two universal data structures that exist in almost every programming language: Objects (key-value pairs) and Arrays (ordered lists).
Here is a classic example of a JSON payload:
{
"user": {
"id": 1056,
"name": "Jane Developer",
"isActive": true,
"skills": ["React", "Go", "PostgreSQL"],
"preferences": null
}
}The Strict Rules of JSON
Unlike standard JavaScript objects, JSON requires strict formatting. A single misplaced comma will cause a parser to fail entirely.
- Keys must be strings enclosed in double quotes. (e.g.,
"name": "Jane"instead ofname: "Jane") - Strings must use double quotes. Single quotes are completely invalid in JSON.
- No trailing commas are allowed. The last item in an object or array cannot have a comma after it.
- Only valid data types: Strings, numbers, objects, arrays, booleans (
true/false), andnull. You cannot store functions or dates in pure JSON.
Why JSON Won the War Against XML
Prior to 2010, XML (Extensible Markup Language) was the standard format for web data. However, XML is verbose, difficult to parse natively in JavaScript, and suffers from heavy payload sizes because every piece of data requires an opening and closing tag (e.g., <name>Jane</name>).
Because JSON maps directly to core JavaScript object principles, manipulating data returned from a JSON API takes virtually zero effort for frontend developers. The payload sizes are dramatically smaller, speeding up network transit times considerably.
Validate and Format Your JSON
Because JSON's syntax is so strict, missing a single double-quote will break your application. Use our free JSON Formatter and Validator to locate syntax errors instantly.