JSON / Data·6 min read·By the StackUtils Team

What is JSON? A Complete Developer's Guide

JSON is the lingua franca of web APIs. Learn its syntax, data types, common errors, and how it compares to XML — with real-world examples.

What Does JSON Stand For?

JSON stands for JavaScript Object Notation. It was conceived by Douglas Crockford in the early 2000s as a lightweight, human-readable alternative to XML for transmitting data between a server and a web application. Despite the name, JSON is language-independent: parsers and serializers exist in every major programming language, from Python and Java to Rust and Go.

JSON became an ECMA standard (ECMA-404) in 2013 and an IETF standard (RFC 8259) in 2017. Today it is the de facto format for REST APIs, configuration files, and data interchange between modern applications.

JSON Syntax Rules

JSON has a minimal, unambiguous syntax. Every valid JSON document follows these rules:

  • Data is represented as name/value pairs separated by colons.
  • Pairs are separated by commas; no trailing comma is allowed.
  • Curly braces {} delimit objects.
  • Square brackets [] delimit arrays.
  • String values must use double quotes — single quotes are invalid.
  • Object keys must be strings (double-quoted).
  • Comments are not allowed in standard JSON.

The Six JSON Data Types

JSON supports exactly six value types. Nothing more, nothing less:

TypeExampleNotes
String"Hello World"Must use double quotes — single quotes are invalid
Number42, 3.14, -7, 2.5e10No distinction between int and float; Infinity and NaN are not allowed
Booleantrue / falseLowercase only — True or False are invalid
NullnullRepresents intentional absence of a value; lowercase only
Object{ "key": "value" }Unordered collection of name/value pairs; keys must be unique strings
Array[ 1, "two", null ]Ordered list of values; types can be mixed

A Real-World JSON Example

Here is a realistic JSON response from a user-management API:

{
  "id": "usr_01HZ9VKPD4R5F6G7H8JK",
  "name": "Jane Smith",
  "email": "jane@example.com",
  "createdAt": "2024-01-15T09:30:00Z",
  "plan": "pro",
  "preferences": {
    "theme": "dark",
    "notifications": true,
    "language": "en"
  },
  "tags": ["developer", "admin"],
  "lastLogin": null
}

This example demonstrates: a nested object (preferences), an array (tags), a null value (lastLogin), and an ISO 8601 date string (createdAt). Note that JSON has no native Date type — dates are always strings by convention.

JSON vs XML: Why JSON Won

Before JSON's rise, XML dominated data interchange. Here is how the two formats compare:

FeatureJSONXML
VerbosityMinimalVery verbose (closing tags)
CommentsNot supportedSupported (<!-- -->)
Data types6 built-in typesEverything is a string
Parsing speedFastSlower
Human readabilityHighMedium
NamespacesNot supportedSupported
Schema validationJSON SchemaXML Schema (XSD)
Common useREST APIs, config filesSOAP, XSLT, SVG, RSS

XML still dominates in enterprise contexts (SOAP, document publishing, SVG), but JSON is the universal choice for REST APIs and modern web development.

The 5 Most Common JSON Errors

  1. Trailing commas { "a": 1, "b": 2, } — The comma after the last value is invalid in JSON (it is valid in JavaScript and JSON5, but not standard JSON).
  2. Single-quoted strings {'key': 'value'} — Both keys and string values must use double quotes.
  3. Unquoted object keys { key: "value" } — All object keys must be quoted strings, unlike JavaScript object literals.
  4. Comments — Neither // inline nor /* block */ comments are allowed. Use JSONC or JSON5 if you need comments in config files.
  5. Undefined and special numbers undefined, Infinity, and NaN exist in JavaScript but are not valid JSON values.

JSON in Practice

JSON appears across virtually every layer of modern web development:

  • REST APIs — Over 95% of public REST APIs use JSON as their response format.
  • Configuration filespackage.json, tsconfig.json, .eslintrc, .prettierrc — the Node.js ecosystem runs on JSON.
  • Databases — MongoDB stores BSON (Binary JSON); PostgreSQL has a native jsonb column type; MySQL supports JSON columns since 5.7.
  • Browser storagelocalStorage and sessionStorage store strings, so data is serialized with JSON.stringify() and deserialized with JSON.parse().
  • Inter-service communication — Microservices typically exchange JSON over HTTP or message queues like Kafka and RabbitMQ.

JSON Schema: Validating JSON Structures

JSON Schema is a vocabulary that describes the structure and constraints of a JSON document. It acts as a contract between API producers and consumers, enabling automated validation, documentation generation, and IDE autocompletion.

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": ["name", "email"],
  "properties": {
    "name":  { "type": "string", "minLength": 1 },
    "email": { "type": "string", "format": "email" },
    "age":   { "type": "integer", "minimum": 0 }
  }
}

This schema validates that a JSON object has a non-empty name, a valid-format email, and an optional non-negative integer age. Libraries like ajv (JavaScript), jsonschema (Python), and com.networknt.json-schema-validator (Java) implement JSON Schema validation.

Work with JSON faster

Use these free browser-based tools to explore, validate, and transform JSON data instantly — no install required.