What is JSON?

A complete guide to the world's most popular data interchange format

JSON in a Nutshell

JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format. It's the standard way applications send and receive data over the internet. When you use a weather app, scroll social media, or make an online purchase, JSON is almost certainly carrying the data between the server and your device.

JSON was derived from JavaScript but is completely language-independent. Every major programming language — Python, Java, Go, C#, Ruby, PHP, Rust, Swift — can read and write JSON. It was specified by Douglas Crockford in the early 2000s and is defined in RFC 8259 and ECMA-404.

JSON Syntax

JSON has just two structures:

  • Objects — unordered collections of key/value pairs, wrapped in curly braces {}
  • Arrays — ordered lists of values, wrapped in square brackets []

A JSON value can be:

  • String"hello world" (always double quotes)
  • Number42, 3.14, -1, 1.5e10
  • Booleantrue or false
  • null — represents an empty value
  • Object — nested objects
  • Array — nested arrays
{
  "name": "Alice",
  "age": 30,
  "isActive": true,
  "email": null,
  "skills": ["JavaScript", "Python", "Go"],
  "address": {
    "city": "San Francisco",
    "zip": "94102"
  }
}

Why JSON Became the Standard

Before JSON, XML was the dominant data format for web APIs. JSON won because it's:

  • Simpler — no closing tags, no attributes, no DTDs. A JSON object is 30-50% smaller than the equivalent XML.
  • Native to JavaScript — browsers can parse JSON with a single JSON.parse() call. No external libraries needed.
  • Human-readable — developers can scan JSON and understand the data structure immediately.
  • Universal — every language has built-in JSON support. No special parser libraries required.

By 2015, JSON had completely replaced XML for web APIs. Today, over 70% of all public APIs use JSON as their primary format.

Common JSON Use Cases

  • REST APIs — almost every REST API sends and receives JSON. When you call GET /api/users, the response is JSON.
  • Configuration filespackage.json (Node.js), tsconfig.json (TypeScript), .eslintrc.json, VS Code settings — all JSON.
  • Databases — MongoDB stores documents as BSON (binary JSON). PostgreSQL has native jsonb columns.
  • Message queues — Kafka, RabbitMQ, and SQS commonly transmit JSON messages.
  • Local storage — browsers store data with localStorage.setItem('key', JSON.stringify(data)).

JSON Rules to Remember

  1. Keys must be strings in double quotes — "name", not name or 'name'.
  2. No trailing commas{"a": 1,} is invalid JSON.
  3. No comments — JSON does not support // or /* */ comments.
  4. No single quotes — strings must use double quotes.
  5. No undefined — use null instead.
  6. Numbers can't have leading zeros07 is invalid, use 7.

JSON in Different Languages

JavaScript

const data = JSON.parse(text)
const text = JSON.stringify(data)

Python

import json
data = json.loads(text)
text = json.dumps(data)

Go

json.Unmarshal([]byte(text), &data)
text, _ := json.Marshal(data)

Java

new ObjectMapper()
  .readValue(text, Map.class)

JSON vs Other Formats

FeatureJSONXMLYAML
ReadabilityGoodVerboseBest
File sizeSmallLargeSmall
CommentsNoYesYes
SchemaJSON SchemaXSD/DTDNo standard
API usageDominantLegacyRare
Config filesCommonRareVery common

Want a deeper comparison? Read our JSON vs YAML vs XML guide.

Work with JSON Online