Skip to content

Article · Data formats

What Is JSON? A Simple Explanation with Examples

JSON is the text format apps and APIs use to exchange data. Learn how it is structured, where it is used, how it compares with XML, and the mistakes that break it.

Author
VoltKit
Published
Reading time
3 min read

JSON (JavaScript Object Notation) is a lightweight text format for storing and exchanging data. When an app asks a server for your profile, the server almost certainly answers in JSON. It looks like this:

{
  "name": "VoltKit",
  "launched": 2026,
  "free": true,
  "categories": ["tools", "games", "learn"]
}

That is a complete JSON document: an object with four keys, whose values are a string, a number, a boolean and an array. It is readable by people and trivially parsed by machines, which is why it has become the default way software talks to software.

The six value types

JSON has only six kinds of value, and every document is built from them:

TypeExampleNotes
String"hello"Always double quotes; backslash escapes such as \n
Number42, -3.5, 1e9No leading zeros, no NaN or Infinity
Booleantrue, falseLowercase only
NullnullRepresents "no value"
Array[1, 2, 3]Ordered list of any values
Object{"key": "value"}Unordered set of key–value pairs; keys are strings

Objects and arrays can nest without limit, so a JSON document can describe anything from a single number to a whole database export.

How JSON is used

  • Web APIs. Nearly every REST API sends and receives JSON. The Content-Type: application/json header tells the receiver how to read the body.
  • Configuration. package.json, tsconfig.json, editor settings and countless other config files are JSON.
  • Storage. Browsers store JSON strings in localStorage; document databases such as MongoDB and CouchDB store JSON-like records natively.
  • Data exchange. Exports, logs and messages between services are commonly JSON because every language has a parser built in.

In JavaScript, converting between text and objects is one call each way:

const text = JSON.stringify({ ok: true }); // '{"ok":true}'
const value = JSON.parse(text);            // { ok: true }

JSON vs XML

Before JSON, XML was the usual exchange format. XML is more verbose (<name>VoltKit</name> versus "name": "VoltKit"), supports attributes, namespaces and schemas, and is still common in enterprise and document systems such as SOAP, RSS and Office files. JSON won the web because it is smaller, maps directly onto the data structures programmers already use, and needs no extra library in the browser.

Common JSON mistakes

Most invalid JSON is JavaScript that is not quite JSON. Watch for:

  • Trailing commas after the last item: {"a": 1,} is invalid.
  • Single quotes or unquoted keys: {'a': 1} and {a: 1} are invalid.
  • Comments, which JSON does not allow.
  • undefined, NaN and Infinity, which have no JSON representation. Use null or a string.
  • Leading zeros such as 007, which must be written as 7 or quoted.

A validator catches all of these and points to the exact line and column:

Check your JSON withJSON Validator
  • YAML is a superset of JSON used for configuration; it trades braces for indentation. The JSON to YAML converter shows the same data in both.
  • CSV is flat and tabular; JSON is nested. The JSON to CSV converter flattens nested keys into columns.
  • JSON Schema describes what a JSON document should contain, so it can be validated automatically.
  • JWT tokens are three Base64-encoded JSON objects joined with dots; the JWT decoder shows them.

Frequently asked questions

Is JSON a programming language?

No. JSON is a data format: a way of writing values down so programs can read them. It has no logic, loops or functions. Its syntax comes from JavaScript, but almost every language can read and write it.

Can JSON contain comments?

No. Standard JSON has no comment syntax. Formats such as JSON5 and JSONC add comments for configuration files, but ordinary JSON parsers reject them.

What is the difference between JSON and a JavaScript object?

JSON is text; a JavaScript object lives in memory. JSON is stricter: keys must be double-quoted strings, there are no trailing commas, no comments, no undefined and no functions.

What file extension does JSON use?

Files use the .json extension, and the media type sent by web servers is application/json.

← Back to Learn

You might also like

Something useful from another corner of VoltKit.