What is JSON?

1

What is JSON?

▶

JSON, which stands for JavaScript Object Notation, is one of the most important data formats in modern web development. At its core, JSON is a plain-text, lightweight format for representing structured data. Because it is plain text, you can open a JSON file in any basic text editor and read it immediately — no special software, no binary decoding, no proprietary tools required. This human-readability is one of the qualities that helped JSON become the dominant data-interchange format on the web.

JSON's syntax is directly derived from the way objects are written as literals in JavaScript. If you have ever written something like { "name": "Alice", "age": 30 } in a JavaScript program, you have already written valid JSON. The similarity is intentional: JSON was formalized by Douglas Crockford in the early 2000s as a minimal subset of JavaScript's object literal notation, stripped down to just the parts needed to describe data. Despite those JavaScript origins, JSON is completely language-independent. Every mainstream programming language — Python, Java, C#, Ruby, PHP, Go, Rust, Swift, and many more — has built-in or widely available libraries for both reading (parsing) and writing (serializing) JSON. This universality is central to JSON's role as a lingua franca for data exchange.

To understand why JSON matters, consider the problem it solves. Modern applications are built from many separate components: a database server, a back-end API, a web browser, a mobile app. These components are often written in different programming languages and run on different machines. They need a way to hand structured data back and forth. JSON provides a neutral, agreed-upon format that every component can produce and consume, regardless of what language it is written in. A Python back end can serialize a dictionary to JSON, send it over HTTP, and a JavaScript front end can parse that JSON string into an object it can work with — no special negotiation required.

Before JSON became widespread, XML (Extensible Markup Language) was the standard format for this kind of data exchange. XML is powerful and flexible, but it is also verbose. Consider representing a single person's name and age in both formats:

<!-- The same data in XML -->
<person>
  <name>Alice</name>
  <age>30</age>
</person>

// The same data in JSON
{
  "name": "Alice",
  "age": 30
}

The JSON version is noticeably shorter. At the scale of a busy API responding to millions of requests per day, smaller payloads mean less bandwidth consumed, faster transmission, and lower costs. JSON also requires less parsing work, making it faster to process. These practical advantages led to JSON displacing XML in the vast majority of new web API designs over the past fifteen years.

JSON Structure and Syntax are defined by just a handful of rules, which is part of what makes the format so approachable.

A JSON object is a collection of key-value pairs enclosed in curly braces { }. Each key must be a double-quoted string, followed by a colon, followed by a value. Multiple key-value pairs are separated by commas. For example:

{
  "firstName": "Alice",
  "lastName": "Smith",
  "age": 30,
  "isStudent": false,
  "score": 98.5,
  "address": null
}

A JSON array is an ordered list of values enclosed in square brackets [ ], with values separated by commas. Arrays can hold any mix of valid JSON value types:

["apple", "banana", "cherry"]

[1, 2, 3, 4, 5]

[true, false, null, 42, "hello"]

The value types that JSON supports are precisely defined:

  • String — a sequence of Unicode characters wrapped in double quotes, e.g., "Hello, world!"
  • Number — an integer or floating-point value, e.g., 42 or 3.14. JSON does not distinguish between integer and float types at the syntax level.
  • Boolean — either true or false (lowercase, no quotes)
  • Null — the value null (lowercase, no quotes), representing the intentional absence of a value
  • Object — a nested { } structure, allowing arbitrarily deep nesting
  • Array — a nested [ ] list, which can itself contain objects or other arrays

This ability to nest objects and arrays inside one another is what makes JSON powerful enough to represent complex, real-world data structures. Here is a more realistic example showing nesting:

{
  "user": {
    "id": 1042,
    "name": "Alice Smith",
    "email": "alice@example.com",
    "roles": ["admin", "editor"],
    "address": {
      "street": "123 Main St",
      "city": "Springfield",
      "country": "US"
    },
    "active": true
  }
}

JSON's simplicity comes with strict rules, and there are several common syntax mistakes that beginners make:

  • Single-quoted strings are not valid. { 'name': 'Alice' } is not JSON. Keys and string values must always use double quotes.
  • Trailing commas are not allowed. { "a": 1, "b": 2, } is invalid because of the comma after the last pair. Many programming languages allow trailing commas in their own syntax, but JSON does not.
  • Comments are not supported. You cannot add // comments or /* block comments */ to JSON. The format contains only data, never annotations. (Some tools support a superset called JSONC for configuration files, but that is not standard JSON.)
  • Unquoted keys are not valid. { name: "Alice" } is a JavaScript object literal syntax, not JSON. JSON always requires quoted keys.
  • Functions and undefined are not valid values. JSON cannot represent executable code or JavaScript's undefined type.

Why JSON is Widely Used on the Web comes down to a combination of technical and practical factors working together. First, JSON is natively understood by JavaScript, the language that runs in every web browser. The browser's JavaScript engine can parse a JSON string into a usable object with a single built-in function call — JSON.parse() — and serialize an object back to a JSON string with JSON.stringify(). No external library is needed.

Second, JSON's lightweight nature has a direct impact on performance. Because JSON payloads are compact, web applications can fetch data faster, especially on mobile networks where bandwidth is limited. APIs that once returned kilobytes of XML markup can return a fraction of that size in JSON, improving response times and reducing server egress costs.

Third, JSON strikes an ideal balance between being machine-parseable and human-readable. Developers can inspect a raw JSON response in a browser's developer tools or a terminal and immediately understand the data structure without running any decoding step. This dramatically speeds up debugging and development.

Fourth, the ecosystem around JSON is mature and comprehensive. There are online validators and formatters (such as JSONLint), editor plugins that syntax-highlight and pretty-print JSON, schema validation tools (like JSON Schema), and database systems (like PostgreSQL and MongoDB) that natively store and query JSON data. This tooling investment reinforces JSON's position as the standard.

The table below summarizes how JSON compares to XML across several practical dimensions:

Dimension JSON XML
Verbosity Compact — minimal punctuation overhead Verbose — opening and closing tags for every element
Human readability Easy to read and write by hand Readable but more cluttered with markup
Native browser support Yes — built into JavaScript engines Requires DOM parsing or external libraries
Comments Not supported Supported natively
Data types Strings, numbers, booleans, null, arrays, objects Everything is text; types inferred or declared via schema
Schema support JSON Schema (external standard) XSD — powerful and widely used
Typical use case Web APIs, configuration files, data storage Document markup, enterprise systems, legacy APIs

An important concept for JavaScript developers is the distinction between JSON and a JavaScript object, because they look very similar but are fundamentally different things. A JavaScript object is a live, in-memory data structure. It can have methods (properties whose values are functions), its keys do not need to be quoted in source code, and it can contain values of any JavaScript type, including undefined, functions, Symbol, and more. JSON, by contrast, is a text string — a sequence of characters. It cannot contain functions, it only supports its own six value types, and its keys must always be double-quoted strings.

The two are related by two operations. When data arrives over a network as a JSON string, you must parse it into a JavaScript object before you can work with its properties:

// A JSON string received from an API
const jsonString = '{"name": "Alice", "age": 30}';

// Parse it into a JavaScript object
const user = JSON.parse(jsonString);

console.log(user.name); // "Alice"
console.log(user.age);  // 30

Conversely, when you want to send a JavaScript object to a server or save it to a file, you must stringify it — serialize it into a JSON-formatted text string:

// A JavaScript object in memory
const user = {
  name: "Alice",
  age: 30,
  greet: function() { return "Hello!"; } // This method will be lost
};

// Serialize it to a JSON string
const jsonString = JSON.stringify(user);

console.log(jsonString);
// Output: '{"name":"Alice","age":30}'
// Note: the greet function is silently dropped because
// functions are not a valid JSON value type

This serialization and deserialization cycle — JSON.parse() to turn a string into an object, JSON.stringify() to turn an object back into a string — is the fundamental workflow whenever a JavaScript application communicates with a server. Understanding that JSON is always text, and that it must be explicitly converted in both directions, prevents a large category of common programming errors where developers accidentally try to access properties on an unparsed string or try to send a raw object where a text payload is expected.

NotesAn introduction to the JSON (JavaScript Object Notation) data format, its purpose, and why it is widely used for data interchange on the web.