Guide

What is JSON? A beginner’s guide with examples

Published November 26, 2026 · 5 min read

JSON is the most common format for sending data between programs. This guide explains its data types and rules with examples, and shows how to use it in code.

What JSON is

JSON (JavaScript Object Notation, pronounced “Jason”) is a plain-text format for storing and sending structured data. It describes data as nested lists and key–value pairs, using a small set of characters: braces, brackets, colons, commas and quotes.

Although the syntax comes from JavaScript, JSON is independent of any programming language. Python, Java, Go, C#, PHP, Rust, Swift and virtually every other language can read and write it, usually with a built-in library. That makes it the default way for programs written in different languages to exchange data.

Here is a small JSON document describing a user:

{
  "id": 42,
  "name": "Ada Lovelace",
  "email": "ada@example.com",
  "admin": false,
  "languages": ["English", "French"],
  "address": {
    "city": "London",
    "postcode": null
  }
}

Even without knowing the rules, you can probably read it: a user with an ID, a name, an email address, a flag saying they are not an admin, a list of languages and a nested address. Being readable by both people and machines is a big part of why JSON became so popular.

A short history

JSON was specified by Douglas Crockford in the early 2000s, who described a subset of JavaScript’s object literal syntax that was easy to parse in any language. Web applications were starting to fetch data in the background, and JSON was much lighter than XML, the main alternative at the time.

Today JSON is defined by two matching standards: ECMA-404 and RFC 8259. Its official media type is application/json, and files usually use the .json extension.

The six data types

Every JSON value is one of exactly six types.

1. Object

An unordered set of key–value pairs inside curly braces. Keys must be strings in double quotes, followed by a colon and a value. Pairs are separated by commas.

{ "city": "London", "population": 8866000 }

2. Array

An ordered list of values inside square brackets, separated by commas. Values can be of mixed types.

[1, "two", true, null, { "five": 5 }]

3. String

Text inside double quotes. Special characters are written with a backslash: \" for a quote, \\ for a backslash, \n for a new line, \t for a tab, and é for any Unicode character by its code.

"She said \"hi\" and left.\nNew line here."

4. Number

An integer or decimal, optionally with an exponent: 42, -7, 3.14, 6.02e23. There is no separate integer and float type.

5. Boolean

Either true or false, always lowercase and without quotes.

6. Null

null, lowercase and without quotes, means “no value”. It is different from an empty string "" or a missing key.

Objects and arrays can contain each other to any depth, which is how JSON represents complex data such as an order with a customer, several items and a shipping address.

Syntax rules that trip people up

JSON looks like JavaScript, but it is much stricter. These are not allowed:

  • Single quotes. {'name': 'Ada'} is invalid. Use {"name": "Ada"}.
  • Unquoted keys. {name: "Ada"} is invalid. Every key needs double quotes.
  • Trailing commas. [1, 2, 3,] and {"a": 1,} are invalid.
  • Comments. Neither // line nor /* block */ comments are part of JSON.
  • Special number values. NaN, Infinity, hexadecimal like 0xFF, leading zeros like 007 and a leading + are invalid.
  • undefined, functions and dates. JSON has no date type. Dates are usually stored as strings in ISO 8601 format, such as "2026-03-14T09:26:53Z".

Whitespace between values is ignored, so {"a":1} and the same object spread over several indented lines are identical. That is why formatting and minifying JSON doesn’t change its meaning.

Duplicate keys in one object, like {"a": 1, "a": 2}, are technically allowed by the grammar, but the standard says keys should be unique, and different parsers handle duplicates differently. Most keep the last value. Avoid them.

Where JSON is used

  • Web APIs. Most REST and many other APIs send and receive JSON. When a website or app loads data in the background, it is very often JSON.
  • Configuration files. package.json in Node.js, tsconfig.json in TypeScript, and settings files in editors like VS Code.
  • Databases. Document databases such as MongoDB and CouchDB store JSON-like documents, and PostgreSQL and MySQL have JSON column types.
  • Logs and events. Structured logging writes one JSON object per line (often called JSON Lines or NDJSON), which is easy to search and parse.
  • Data exchange. Exports, webhooks, message queues and many file formats are built on JSON.

Reading and writing JSON in code

JavaScript

// Text → object
const user = JSON.parse('{"name": "Ada", "age": 36}')
console.log(user.name) // "Ada"

// Object → text (2-space indentation)
const text = JSON.stringify(user, null, 2)

Python

import json

user = json.loads('{"name": "Ada", "age": 36}')
print(user["name"])  # Ada

text = json.dumps(user, indent=2)

In both languages, parsing turns JSON text into native objects, lists, strings and numbers, and serializing (stringify or dump) turns them back into text. If the text isn’t valid JSON, parsing throws an error. Our guide to fixing JSON errors explains what those messages mean.

A note on large numbers

JSON itself puts no limit on the size or precision of numbers, but many languages do when they parse it. JavaScript stores every number as a 64-bit floating-point value, which can only represent integers exactly up to 253 − 1 (9,007,199,254,740,991). Parsing {"id": 12345678901234567890} with JSON.parse silently gives 12345678901234567000.

This regularly breaks 64-bit database IDs and similar values. Common fixes are to send such values as strings ("id": "12345678901234567890") or to use a parser that keeps numbers exactly. The 2JSON viewer uses such a parser, so large numbers display exactly as they appear in your data.

Tools for working with JSON

Summary

  • JSON is a text format for structured data built from objects, arrays, strings, numbers, booleans and null.
  • Keys and strings use double quotes. Comments, trailing commas and single quotes are not allowed.
  • It is the standard format for web APIs and is supported by almost every programming language.
  • Watch out for very large integers, and store dates as ISO 8601 strings.