JSON Explained: What It Is, How It Works, and How to Use It
The complete JSON guide: what JSON stands for, all six data types, syntax rules, how APIs use JSON, JavaScript vs JSON differences, and how to parse and stringify JSON in code.
JSON (JavaScript Object Notation) is a lightweight, text-based format for storing and exchanging data. It is the universal data format of the modern web — used by virtually every API, database, and configuration system. JSON is human-readable, language-independent, and directly parseable by JavaScript, Python, Ruby, Go, and every other mainstream programming language without any additional libraries.
What does JSON stand for?
JSON stands for JavaScript Object Notation. Despite the name, JSON is not limited to JavaScript — it is a language-independent text format defined by the IETF in RFC 8259 and used across every programming ecosystem. It was created by Douglas Crockford around 2001 as a simpler alternative to XML for transmitting data between a server and a web application.
What does JSON look like?
JSON represents data as key-value pairs wrapped in curly braces. Here is a complete example representing a user object:
{
"id": 1042,
"name": "Alice Chen",
"email": "alice@example.com",
"age": 31,
"is_active": true,
"score": 9.7,
"tags": ["developer", "python", "api"],
"address": {
"city": "San Francisco",
"country": "US"
},
"last_login": null
}This example shows all six JSON data types: string ("Alice Chen"), number (1042, 9.7), boolean (true), array (["developer", ...]), object ({"city": ...}), and null (null).
What data types does JSON support?
JSON supports exactly six data types — no more, no less:
| Type | Example | Notes |
|---|---|---|
| String | "Hello world" | Must use double quotes — single quotes are invalid JSON |
| Number | 42, 3.14, -7 | No distinction between integer and float |
| Boolean | true, false | Lowercase only — True and False are invalid |
| Null | null | Represents the intentional absence of a value |
| Array | [1, "two", true] | Ordered list of any JSON values |
| Object | {"key": "value"} | Unordered collection of key-value pairs |
JSON does not support: dates (stored as strings), undefined, comments, functions, or binary data.
What are the rules of JSON syntax?
JSON has strict syntax rules that differ from JavaScript object literals:
- Keys must be strings in double quotes —
{"name": "Alice"}not{name: "Alice"} - Strings must use double quotes —
"value"not'value' - No trailing commas —
{"a": 1, "b": 2}not{"a": 1, "b": 2,} - No comments —
// thisand/* this */are not valid JSON - Numbers have no leading zeros —
042is invalid
These rules are the source of virtually every JSON.parse() error developers encounter. For a complete guide to diagnosing and fixing JSON syntax errors, see how to fix JSON parse errors and unexpected token issues.
How is JSON used in APIs?
JSON is the default data format for REST APIs and GraphQL APIs. When your application makes an HTTP request to an API endpoint, the server responds with a JSON body that your code parses into objects. Here is the complete flow:
// 1. Make an API request
const response = await fetch('https://api.example.com/users/1042');
// 2. Parse the JSON response
const user = await response.json();
// 3. Use the data
console.log(user.name); // "Alice Chen"
console.log(user.tags); // ["developer", "python", "api"]response.json() calls JSON.parse() on the response body. If the server returns invalid JSON (an error page in HTML, a malformed response, a truncated body), the parse call throws a SyntaxError.
What is the difference between JSON and a JavaScript object?
JSON is a text format — a string. A JavaScript object is an in-memory data structure. They look similar but are not the same:
| Feature | JSON (text format) | JavaScript object |
|---|---|---|
| Type | String | Object in memory |
| Keys | Must be double-quoted strings | Can be unquoted identifiers |
| Strings | Double quotes only | Single or double quotes |
| Trailing commas | Not allowed | Allowed |
| Comments | Not allowed | Allowed |
| Functions | Not allowed | Allowed |
| Convert to object | JSON.parse(jsonString) | Already an object |
| Convert to JSON | Already JSON | JSON.stringify(obj) |
How do you format and validate JSON?
Minified JSON (no whitespace) is compact but unreadable. Pretty-printed JSON adds indentation and line breaks to make the structure visible. Both represent identical data — only the whitespace differs.
To format JSON in JavaScript: JSON.stringify(data, null, 2) — the third argument sets the indentation level. To validate that a string is valid JSON before parsing, wrap JSON.parse() in a try-catch.
For formatting, validating, and fixing broken JSON online, use the JSON Formatter & Validator. For a step-by-step guide to formatting JSON including minification and error fixing, see how to format and validate JSON.
What is the difference between JSON and XML?
Both JSON and XML are data interchange formats, but they differ significantly in verbosity and use cases. JSON is more compact, directly parseable by JavaScript, and the dominant format for web APIs since around 2010. XML is more verbose, supports document-centric content with mixed text and tags, and is still common in enterprise systems, SOAP services, and document formats like SVG and RSS.
For a detailed comparison of when to use each format, see JSON vs XML — which should you use for your API?
Key takeaways
- JSON (JavaScript Object Notation) is a text-based data format used by virtually every web API and configuration system.
- JSON supports six data types: string, number, boolean, null, array, and object.
- JSON syntax is stricter than JavaScript: keys must be double-quoted, no trailing commas, no comments, no functions.
- In JavaScript:
JSON.parse(string)converts JSON text to an object.JSON.stringify(obj)converts an object to JSON text. - JSON parse errors almost always come from one of five causes: trailing comma, single quotes, unquoted key, missing comma, or a comment.
Frequently asked questions
Is JSON the same as JavaScript?
No. JSON is a text format inspired by JavaScript object literal syntax, but it is language-independent. Python, Ruby, Go, Java, and every mainstream language can parse JSON natively. The name "JavaScript Object Notation" refers to its syntactic origin, not a dependency on JavaScript.
What is JSON used for?
JSON is used for three main purposes: API responses (servers send data to clients), configuration files (package.json, tsconfig.json, settings.json), and data storage in NoSQL databases (MongoDB, Firebase, DynamoDB store data as JSON documents).
Can JSON contain comments?
No — standard JSON does not support comments. If you need comments in a JSON-like config file, use JSONC (JSON with Comments — supported by VS Code and TypeScript) or JSON5. Both are supersets of JSON. Standard JSON.parse() rejects both; you need a compatible parser.
What is the difference between JSON and YAML?
YAML (YAML Ain't Markup Language) is another human-readable data format, commonly used for configuration files (Docker Compose, Kubernetes, GitHub Actions). YAML supports comments, is less verbose than JSON, but is whitespace-sensitive and easier to accidentally break. JSON is better for API data interchange; YAML is often preferred for configuration files that humans frequently edit.
Why does JSON not support dates?
The JSON specification deliberately excludes a date type because date formats vary globally and are context-dependent. The convention is to represent dates as ISO 8601 strings: "2026-06-15T09:00:00Z". When parsed, your application code converts the string to a native date object using new Date("2026-06-15T09:00:00Z")in JavaScript or datetime.fromisoformat() in Python.
Free tool
Try the JSON Formatter & Validator
Use our free json formatter & validator to calculate results instantly — no signup required.
Open JSON Formatter & Validator →