What is JSON?

JSON explained: data types, syntax rules, and why it became the universal data format for APIs and config files.

6 min read·Updated June 2026

JSON (JavaScript Object Notation) is a lightweight text format for storing and exchanging structured data. It was standardised in RFC 8259 and is now the default data format for REST APIs, configuration files, databases, and practically everything that passes data between systems.

JSON was derived from JavaScript object literal syntax in the early 2000s, but it is completely language-agnostic — every major programming language can read and write it natively.

The 6 JSON data types

JSON supports exactly six value types. Nothing else is valid.

string
"Hello""2024-01-31"""

Always double-quoted. Single quotes are invalid.

number
423.14-71.5e10

Integer or float. No NaN, no Infinity, no hex.

boolean
truefalse

Lowercase only. True and False are invalid.

null
null

Represents the intentional absence of a value.

array
[1, 2, 3]["a", "b"][]

Ordered list of any JSON values. Can be mixed types.

object
{"key": "val"}{}

Unordered key-value pairs. Keys must be strings.

Syntax rules

JSON has a small, strict set of rules. Break any one of them and the document is invalid.

Keys must be double-quoted strings
✅ valid{"name": "Alice"}
❌ invalid{name: "Alice"}
Strings use double quotes only
✅ valid"hello"
❌ invalid'hello'
No trailing commas
✅ valid{"a": 1, "b": 2}
❌ invalid{"a": 1, "b": 2,}
No comments
✅ valid{"rate": 0.15}
❌ invalid{"rate": 0.15} // VAT
Numbers have no leading zeros
✅ valid{"code": 7}
❌ invalid{"code": 007}
No undefined, NaN, or Infinity
✅ valid{"val": null}
❌ invalid{"val": undefined}

JSON vs XML

Before JSON, XML dominated data exchange. Here is the same data in both formats.

JSON 66 chars
{
  "name" "Alice"
  "age" 30
  "admin" true
  "tags" ["dev" "ops"]
}
XML 122 chars
<user>
  <name>Alice</name>
  <age>30</age>
  <admin>true</admin>
  <tags>
    <tag>dev</tag>
    <tag>ops</tag>
  </tags>
</user>
JSONXML
VerbosityCompactVerbose
Native typesnumber, boolean, null, arrayStrings only (attributes aside)
CommentsNot supportedSupported
Schema validationJSON SchemaXSD, DTD
Human-readableEasyCluttered with tags
Parse speedFastSlower
Still used forAPIs, config, storageSOAP, SVG, Office docs

Where JSON is used

REST APIs
The standard format for request and response bodies. Every HTTP client and server library speaks JSON.
Content-Type: application/json
⚙️
Configuration files
Package manifests, IDE settings, and tool configs use JSON for its simplicity and wide tooling support.
package.json, tsconfig.json, .eslintrc
🗄️
Databases
Document databases like MongoDB store records as JSON. PostgreSQL and MySQL have native JSON column types.
db.users.find({ active: true })
💾
Browser storage
localStorage and sessionStorage only store strings — JSON.stringify/parse bridges the gap for objects.
localStorage.setItem("prefs", JSON.stringify(obj))

Frequently asked questions