Skip to content

JavaScript Object Notation (JSON)

JavaScript Object Notation (JSON) is a text format for structured data that borrows the syntax of JavaScript object and array literals, so programs written in any language can exchange values as plain text. JavaScript reads and writes it through the JSON global object. Its JSON.parse() method turns JSON text into values, and JSON.stringify() turns values into JSON text.

A JSON text holds one value, which is an object, an array, a string, a number, true, false, or null. Objects and arrays nest to any depth. The grammar is stricter than JavaScript’s. Strings and property names take double quotes, and JSON has no comments, trailing commas, leading zeros, undefined, NaN, or Infinity.

ECMA-404 and RFC 8259 define the format independently of any one language. JSON exchanged between systems is encoded in UTF-8 and labeled with the application/json media type. In everyday JavaScript, it shows up in API responses read with fetch(), in package.json files, and in JSON modules. Since ES2025, an ES module can import a JSON file with with { type: "json" }. The feature is Baseline Newly available since 2025.

Since ES2019, every JSON text is also a valid JavaScript expression. The reverse doesn’t hold, so text written with object-literal habits often fails to parse as JSON.

Example

Say an order service receives a request body as JSON text. The body is a string until a parser turns it into JavaScript values:

Language: JavaScript
> const body = '{"id": 7, "tags": ["new"], "paid": false, "coupon": null}';
undefined

> JSON.parse(body)
{ id: 7, tags: [ 'new' ], paid: false, coupon: null }

Parsing the string produces an ordinary object holding a number, an array, a Boolean, and null.

A teammate later edits a settings file by hand and writes it the way a JavaScript object literal allows. An unquoted property name, single quotes, and a trailing comma are each valid in an object literal but invalid in JSON:

Language: JavaScript
> JSON.parse('{theme: "dark"}')
Uncaught:
SyntaxError: Expected property name or '}' in JSON at position 1 (line 1 column 2)
> JSON.parse("{'theme': 'dark'}")
Uncaught:
SyntaxError: Expected property name or '}' in JSON at position 1 (line 1 column 2)
> JSON.parse('{"theme": "dark",}')
Uncaught:
SyntaxError: Expected double-quoted property name in JSON at position 17 (line 1 column 18)

Each text throws a SyntaxError, because JSON.parse() accepts only what the JSON grammar allows.

Developer at a sorting machine sending curly-brace parcels to a browser, API, and robot arm under JSON, and angle-bracket parcels to SVG and RSS under XML

Tutorial

JSON vs XML: Why JSON Won the Web and Where XML Still Fits

JSON vs XML: JSON wins for APIs, browsers, and AI tools; XML still runs SVG, RSS, Office files, and SOAP. How it happened, and when to use each.

intermediate node

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 19, 2026