Skip to content
Tools

What Is JSON? Syntax Rules, Data Types and Examples

· 5 min read

JSON (JavaScript Object Notation) is a lightweight, text-based format for storing and exchanging structured data, built from key/value objects and ordered arrays. It is language-independent, readable by humans and parsed by virtually every programming language, which is why most web APIs and many config files use it.

JSON is defined by two matching standards, IETF RFC 8259 and ECMA-404. Its grammar is small enough to learn in ten minutes. To experiment while you read, paste any example below into the JSON formatter to indent it and see exactly where it breaks if you get a rule wrong.

A JSON example

One object that uses all six JSON data types.
{
  "id": 1024,
  "name": "Ada Lovelace",
  "email": "ada@example.com",
  "verified": true,
  "score": 98.5,
  "manager": null,
  "roles": ["admin", "editor"],
  "address": {
    "city": "London",
    "postcode": "W1A 1AA"
  }
}

The outer { } is an object. Each line inside is a key (always a double-quoted string), a colon, and a value. roles holds an array and address holds another object, which is how JSON represents nested data.

The 6 JSON data types

TypeExampleRules
String"hello"Double quotes only. Escape " and \ with a backslash; control characters must be escaped (\n, \t, \u00e9).
Number42, -3.14, 6.02e23Decimal only. No leading zeros (07), no leading +, no hex, no NaN or Infinity. No separate integer and float types.
Booleantrue, falseLowercase only.
NullnullLowercase. Means "no value".
Object{"a": 1, "b": 2}Unordered set of name/value pairs in braces. Keys must be strings and should be unique.
Array[1, "two", null]Ordered list in brackets. Values can be of mixed types.

There is no date, binary or undefined type. Dates are normally sent as ISO 8601 strings ("2026-11-02T09:30:00Z") and binary data as Base64 strings; the receiving program converts them.

JSON syntax rules

  1. Data is name/value pairs: "name": value.
  2. Pairs and array items are separated by commas, with no trailing comma after the last one.
  3. Keys and strings use double quotes. Single quotes are invalid.
  4. Objects use { }, arrays use [ ].
  5. No comments of any kind (// or /* */).
  6. true, false and null are lowercase and unquoted.
  7. Whitespace between tokens (spaces, tabs, line breaks) is ignored, so the same data can be minified or indented.
  8. A JSON text can be any value at the top level, not only an object or array; "hi" and 42 are valid JSON documents under RFC 8259.

Breaking any of these produces a parse error such as "Unexpected token". The most frequent culprits, with fixes, are listed in common JSON errors and how to fix them, and the JSON validator points to the exact line and column.

Object vs array: which to use

Object { }Array [ ]
HoldsNamed fieldsA list of values
Access byKey: user.namePosition: users[0]
OrderNot guaranteed by the specPreserved
Use forOne thing with properties (a user, a config)Many things of the same kind (users, line items)

The common pattern is an array of objects: [{"id": 1}, {"id": 2}]. APIs often wrap that in an object so they can add metadata later, for example {"data": [...], "next": "cursor"}.

JSON vs a JavaScript object

JSON syntax was taken from JavaScript object literals, but JSON is a string format and much stricter.

FeatureJSONJavaScript object literal
Key quotesRequired, double quotesOptional for simple names
String quotesDouble onlySingle, double or backticks
Trailing commasNot allowedAllowed
CommentsNot allowedAllowed
Values6 types onlyAny value: functions, undefined, Date, NaN
What it isText (a string)An in-memory value
const text = '{"name":"Ada","age":36}';
const obj = JSON.parse(text);     // text -> object
obj.age += 1;
const back = JSON.stringify(obj); // object -> text: '{"name":"Ada","age":37}'

Relaxed variants such as JSON5 and JSONC add comments and trailing commas for config files; see JSON vs JSON5 vs JSONC for when those are acceptable.

What JSON is used for

  • Web APIs: most REST APIs send and receive JSON bodies.
  • Configuration: package.json, tsconfig.json, VS Code settings, cloud templates.
  • Data storage and logs: document databases store JSON-like documents; structured logs often use one JSON object per line (NDJSON).
  • Data exchange between languages: a Python service and a Go service can share JSON without either knowing the other's types. To get typed code from a sample, generators such as JSON to TypeScript build the interfaces for you.
  • LLM structured output: AI models are asked to reply in JSON so programs can read the result.
  • Validation contracts: JSON Schema describes which fields and types a document must have.

File extension, MIME type and encoding

  • File extension: .json.
  • MIME / Content-Type: application/json. Do not use text/json, which is unregistered.
  • Encoding: RFC 8259 requires UTF-8 for JSON exchanged between systems, and a byte order mark must not be added.
  • A .json file is plain text and opens in any text editor; see how to open a JSON file on each platform, or load it into the JSON tree viewer to explore nested data.

A brief history

Douglas Crockford specified and popularized JSON in the early 2000s as a simpler alternative to XML for browser-server communication. It became ECMA-404 in 2013 and an IETF standard track RFC in 2014 (RFC 7159). The current versions, RFC 8259 and the second edition of ECMA-404, were both published in December 2017 and describe the same syntax.

FAQ

What does JSON stand for?

JavaScript Object Notation. The name reflects its origin in JavaScript object literal syntax, but JSON is language-independent.

Is JSON a programming language?

No. JSON is a data format: it describes values but has no variables, logic or functions, so it cannot run.

Is JSON case sensitive?

Yes. Keys are compared exactly, so "Name" and "name" are different keys, and the literals true, false and null must be lowercase.

What is the MIME type for JSON?

application/json, with the .json file extension. JSON exchanged between systems must be encoded as UTF-8.

Can JSON have comments?

No. Standard JSON does not allow comments. Formats such as JSONC and JSON5 add them, but strict JSON parsers will reject the file.

More JSON guides