What is JSON? The complete guide to JavaScript Object Notation
JSON (JavaScript Object Notation) is an open, language-independent, text-based data interchange format derived from JavaScript object syntax. It represents data as a small set of types — objects, arrays, strings, numbers, booleans, and null — and is the de facto format for web APIs, configuration files, and data exchange between servers and clients. This guide explains JSON's syntax, its data types, how it compares to XML and YAML, and how to parse and generate it.
On this page
- What makes JSON so widely used?
- The JSON data types
- JSON's strict syntax rules
- JSON and JavaScript: parse and stringify
- JSON vs XML vs YAML
- When and where JSON appears
- FAQ
- What does JSON stand for?
- Is JSON a programming language?
- What are the valid data types in JSON?
- What is the difference between JSON and XML?
JSON (JavaScript Object Notation) is an open, text-based, language-independent data interchange format that represents structured data using a small set of types: objects, arrays, strings, numbers, booleans, and null. It was derived from JavaScript object syntax, and it is now standardized by both the IETF (RFC 8259, Internet Standard STD 90) and Ecma International (ECMA-404). In practice, JSON is the de facto format for web APIs, for configuration files, and for exchanging data between a server and a client. This guide covers its syntax and data types, how it relates to JavaScript, how it compares to XML and YAML, and how to parse and generate it.
What makes JSON so widely used?
JSON's design goals, set out in RFC 8259, are that it be minimal, portable, textual, and a subset of JavaScript. Those four properties explain its dominance:
- It is tiny and readable. There is no tag markup, no namespace syntax, no schema language required to read a small document — a human can scan a JSON object and understand it at a glance.
- It is language-independent. Although it looks like JavaScript, standard libraries in almost every programming language can parse and generate JSON. You send JSON from a JavaScript client, a Python server, or a Go service, and any of them can read it.
- It transmits cleanly over the network. Because JSON is just text encoded in UTF-8, it fits naturally into HTTP request and response bodies, and it is trivial to log, cache, and test.
- It is strict enough to be unambiguous. The small, well-defined grammar means two different implementations agree on the same document — the property that made it possible to build interoperability across the web.
The JSON data types
A JSON document can be any one of the following values:
- Object — an unordered collection of zero or more name/value pairs, written as
{ "name": value, ... }. The names are strings, and the values can be any JSON type. Curly braces delimit the object and a colon separates each name from its value. - Array — an ordered sequence of zero or more values, written as
[ value, value, ... ]with square brackets. The values can be any JSON type, and an array's elements do not have to be the same type. - String — a sequence of zero or more Unicode characters enclosed in double quotes, with a backslash escaping syntax for special characters.
- Number — a signed decimal number that may contain a fractional part and may use exponential (E) notation. JSON makes no distinction between integer and floating point, and it cannot represent
NaNorInfinity. - Boolean — the literal value
trueorfalse. - null — the literal word
null, representing an empty value.
A simple example of a complete JSON object:
{
"name": "Debod",
"isActive": true,
"posts": 54,
"tags": ["json", "api"],
"meta": { "editor": "Hermes", "reviewed": null }
}
JSON's strict syntax rules
JSON is a subset of JavaScript object literal syntax, but it is stricter in ways that matter:
- Strings must use double quotes (
"name"), never single quotes. - Every key must be quoted. In JavaScript you can write
{name: "x"}; in JSON you must write{"name": "x"}. - No trailing commas. A comma after the last element in an object or array is invalid in JSON, though it is common in JavaScript.
- No comments. JSON deliberately has no comment syntax. Douglas Crockford removed comments because people used them to hold parsing directives, which would have destroyed interoperability.
- Only serializable types are allowed. JSON cannot represent functions,
Date,Set,Map,undefined,NaN, orInfinity. - Numbers use decimal notation. There is no support for hex literals or leading zeros.
Because the grammar is so confined, a single misplaced comma or missing quote makes a JSON document invalid. That strictness is a feature: it keeps every conforming parser in agreement.
JSON and JavaScript: parse and stringify
Even though JSON is not JavaScript, the JSON object in JavaScript provides the two operations you need almost every day:
JSON.stringify(value)— converts a JavaScript object or array into a JSON string so it can be stored or transmitted.JSON.parse(string)— converts a JSON string back into a JavaScript object so you can read its values.
These map to the general concepts of serialization (object → text) and deserialization (text → object). On the web, you also meet JSON through the Fetch API: response.json() reads a response body and returns a JavaScript object directly.
JSON vs XML vs YAML
JSON is not the only text data format, but it holds a particular niche:
- JSON vs XML. JSON needs far less markup — no closing tags, no namespaces — so the same data is shorter and easier to read. XML predates JSON and is still used where complex document structure, namespaces, or strict schema validation (XSD) are required. For typical API payloads and config, JSON is the lighter, more common choice.
- JSON vs YAML. YAML 1.2 is a superset of JSON, meaning any valid JSON is valid YAML. YAML adds comments, multi-line strings, and a more readable indentation-based syntax, which makes it popular for configuration files where humans edit by hand. But YAML's syntax is richer and its parsers more varied, so JSON remains the safer choice for program-to-program data exchange.
In short, use JSON when data crosses a network or is read by programs; use YAML when humans hand-edit configuration; use XML when you need namespaces, attributes, or formal document schemas.
When and where JSON appears
JSON's stamp is everywhere in modern development:
- Web APIs. REST and GraphQL APIs return JSON bodies;
Content-Type: application/jsonis the norm for request and response payloads. Tools like Postman, Insomnia, and Swagger are built around it. - Configuration and metadata.
package.json, TypeScript config, VS Code settings, and countless tool manifests are JSON (or JSONC, which adds comments and trailing commas). JSON-LD, used for structured data on the web, is JSON that carries linked-data semantics. - Databases. Document databases like MongoDB store records as BSON (a binary superset of JSON). PostgreSQL, MySQL, and SQL Server all support a native JSON type and query operators.
- Client/server communication. Sending structured data from a browser to a server, or between microservices, is almost always done with JSON today.
FAQ
What does JSON stand for?
JSON stands for JavaScript Object Notation. It is a data interchange format derived from JavaScript object syntax, standardized by RFC 8259 (an IETF Internet Standard, STD 90) and by ECMA-404.
Is JSON a programming language?
No. JSON is a data interchange format, not a language. It contains only data — no functions, variables, or logic — and it can be parsed and generated by standard libraries in almost any programming language.
What are the valid data types in JSON?
JSON supports six types: objects (name/value pairs in curly braces), arrays (ordered lists in square brackets), strings (double-quoted Unicode text), numbers (decimal values, optionally with fractions or exponents), booleans (true/false), and null. It cannot represent functions, dates, sets, maps, undefined, NaN, or Infinity.
What is the difference between JSON and XML?
JSON is a compact, minimal format derived from JavaScript, using objects, arrays, and quoted keys with no closing tags or namespaces. XML is an older markup format with opening and closing tags, attributes, and namespaces. For API payloads and configuration, JSON is shorter and more common; XML is still used where complex document structure, namespaces, or XSD schema validation are required.
Sources
- RFC 8259 — JSON Data Interchange Format (rfc-editor.org
- IETF Internet Standard STD 90)
- MDN — Working with JSON (developer.mozilla.org
- CC-BY-SA 2.5+)
- Wikipedia — JSON (en.wikipedia.org
- CC BY-SA 4.0)
Share this guide
Related guides
- REST API design best practices: resource naming, HTTP methods, and status codes
How to design a clean REST API: plural resource URLs, safe and idempotent HTTP methods, meaningful status codes, pagination, and error responses — with practical examples.
- What is an API? A plain-language guide to how APIs work
What an API is, how REST APIs work over HTTP, the methods you'll actually meet — GET, POST, PUT, PATCH, DELETE — and how to read a response.
- What is a Regular Expression (regex)? A practical guide
A regular expression (regex or regexp) is a sequence of characters that forms a search pattern for matching and manipulating text. Built on a formal mathematical foundation and common to almost every programming language and tool, regex lets you validate input, find and replace text, extract data, and transform strings with a compact, declarative syntax. This guide explains what regex is, its core syntax, how it is implemented, and how to use it safely.