JSON is the data format that powers modern web APIs, configuration files, and countless developer tools. If you have ever inspected a network request or edited a config file, you have already read JSON. Here is a clear, practical guide to what it is and how it works.
What Is JSON?
JSON (JavaScript Object Notation) is a lightweight, text-based data format for storing and exchanging structured data as human-readable key–value pairs. It is language-independent, so almost every programming language can read and write it. A minimal JSON document looks like this:
{ "name": "Ada", "age": 36 }
That single object has two fields: name (a string) and age (a number). From this basic shape—keys paired with values—JSON scales up to describe anything from a user profile to an entire application configuration.
JSON was created by Douglas Crockford in the early 2000s as a simpler alternative to XML. Its syntax mirrors JavaScript object literals, which made it a natural fit for the web, but today it is the default data format for REST APIs, NoSQL databases, and config files across every language and platform.
A more complete example:
{
"name": "Ada",
"age": 36,
"isActive": true,
"roles": ["admin", "editor"],
"address": {
"city": "London",
"zip": "EC1A"
}
}
JSON Syntax Rules
JSON has strict, unambiguous syntax—stricter than JavaScript itself.
1. Data is written as key–value pairs
"key": "value"
2. Keys must be strings in double quotes
{"name": "Ada"} ✓ Valid
{name: "Ada"} ✗ Invalid (unquoted key)
{'name': 'Ada'} ✗ Invalid (single quotes)
3. Values must be a valid JSON type
A string, number, boolean, null, array, or object—nothing else.
4. Items are separated by commas, with no trailing comma
{"a": 1, "b": 2,} ✗ Invalid
{"a": 1, "b": 2} ✓ Valid
5. No comments
JSON does not support comments. It is a data format, not a document format.
JSON Data Types
JSON supports exactly six data types. Three are primitives (string, number, boolean), one is the empty value (null), and two are containers (object, array).
String
Text in double quotes. Special characters are escaped with a backslash:
{
"simple": "Hello",
"quoted": "She said \"Hi\"",
"multiline": "Line 1\nLine 2",
"unicode": "Smiley: \u263A"
}
Escape sequences: \" \\ \/ \b \f \n \r \t \uXXXX.
Number
No quotes. Integers, decimals, and scientific notation are all valid:
{ "integer": 42, "negative": -17, "decimal": 3.14, "scientific": 1.23e10 }
There is no hex (0xFF), octal (077), or leading zeros, and NaN/Infinity are not valid JSON.
Boolean
Lowercase true or false only:
{ "active": true, "deleted": false }
Null
Represents the intentional absence of a value:
{ "middleName": null }
Object
An unordered collection of key–value pairs in curly braces:
{ "name": "Bob", "age": 25 }
Array
An ordered list of values in square brackets:
{ "numbers": [1, 2, 3], "mixed": [1, "two", true, null] }
JSON Structure: Objects and Arrays
Every JSON document is built from two container types, and knowing when to use each is the key to well-structured data.
Use an object {} for named properties, where each value has a meaningful key:
{ "name": "Product", "price": 29.99, "inStock": true }
Use an array [] for an ordered collection of similar items:
{ "tags": ["electronics", "sale", "featured"] }
The two combine to form the most common shape in real APIs—an array of objects, which maps neatly onto rows and columns:
{
"users": [
{ "id": 1, "name": "Alice" },
{ "id": 2, "name": "Bob" }
]
}
Because objects and arrays can hold other objects and arrays, JSON can describe deeply nested, hierarchical data:
{
"company": "Tech Corp",
"departments": [
{
"name": "Engineering",
"employees": [
{ "name": "Alice", "skills": ["Python", "JavaScript"] }
]
}
]
}
This nesting is what CSV cannot do—see CSV Files Explained for how flat, tabular data compares.
Valid vs Invalid JSON
Most JSON errors come from treating it like JavaScript or a relaxed config syntax. These are the mistakes a parser will reject:
| Mistake | Invalid | Valid |
|---|---|---|
| Single quotes | {'name': 'Ada'} |
{"name": "Ada"} |
| Unquoted keys | {name: "Ada"} |
{"name": "Ada"} |
| Trailing comma | {"a": 1,} |
{"a": 1} |
| Comments | {"a": 1} // note |
{"a": 1} |
| Unescaped backslash | {"path": "C:\Users"} |
{"path": "C:\\Users"} |
| Raw newline in string | a literal line break | {"text": "a\nb"} |
A few rules worth calling out:
- Trailing commas are valid in modern JavaScript but never in JSON.
- Single quotes are never allowed—strings and keys both require double quotes.
- Comments (
//or/* */) are not part of JSON; if you need them, use YAML or a JSONC variant.
When in doubt, paste your data into a validator. Our JSON Formatter and Validator pinpoints the exact line and character where JSON breaks.
JSON vs XML vs YAML
JSON is one of three data formats you will meet constantly. Here is how they compare:
| Feature | JSON | XML | YAML |
|---|---|---|---|
| Syntax | {"k": "v"} |
<k>v</k> |
k: v |
| Verbosity | Compact | Verbose | Minimal |
| Data types | Yes | All text | Yes |
| Arrays | Native | Conventions | Native |
| Comments | No | Yes | Yes |
| Whitespace significant | No | No | Yes |
| Best for | APIs, data | Documents | Config files |
JSON won for APIs because it is compact, fast to parse, and natively supported in browsers. XML remains useful for documents that need attributes, namespaces, and comments. YAML is a superset of JSON that trades braces for indentation, which makes it popular for human-edited configuration—see JSON vs YAML for a deeper comparison.
Working with JSON in Code
Every major language has built-in JSON support.
JavaScript:
const obj = JSON.parse('{"name": "Ada"}'); // string → object
const json = JSON.stringify(obj, null, 2); // object → pretty string
Python:
import json
obj = json.loads('{"name": "Ada"}') # string → dict
text = json.dumps(obj, indent=2) # dict → JSON string
Always wrap parsing of untrusted input in error handling—invalid JSON throws:
try {
const data = JSON.parse(userInput);
} catch (e) {
console.error("Invalid JSON:", e.message);
}
Converting and Formatting JSON
JSON rarely lives alone. You will often need to reshape it into another format or clean it up:
- Format and validate messy JSON with the JSON Formatter.
- Flatten to a spreadsheet using JSON to CSV, or go the other way with CSV to JSON.
- Convert to config with JSON to YAML.
- Migrate legacy data using XML to JSON.
For transmission, JSON is usually minified ({"name":"Ada","age":36}) to save bytes, then pretty-printed with indentation when you need to read it.
Summary
- JSON is a lightweight, text-based format for structured data, built from key–value pairs.
- It supports six data types: string, number, boolean, null, object, and array.
- Syntax is strict: double quotes only, no trailing commas, no comments.
- Objects hold named properties; arrays hold ordered lists; together they nest to describe any data.
- It is language-independent and the default format for web APIs and configuration.
Frequently Asked Questions
What is JSON format?
JSON format is a text-based way of writing structured data as key–value pairs inside objects {} and arrays []. A value can be a string, number, boolean, null, object, or array. Because it is plain text, JSON can be read by humans and parsed by nearly every programming language, which is why it is the standard for web APIs.
What is JSON notation?
"JSON notation" refers to the syntax JSON uses to write data: keys and string values in double quotes, colons between keys and values, commas between items, curly braces for objects, and square brackets for arrays. The name itself—JavaScript Object Notation—describes this notation, which is modeled on JavaScript object literals.
What data types does JSON support?
JSON supports six types: string (double-quoted text), number (integer or decimal), boolean (true/false), null, object (key–value pairs), and array (ordered list). There is no separate date, integer-vs-float, or binary type—dates are usually stored as ISO 8601 strings.
What is the difference between a JSON object and a JSON array?
An object {} is an unordered set of named key–value pairs—use it when each value has a distinct label, like "name" or "price". An array [] is an ordered list of values accessed by position—use it for collections of similar items. The two are frequently combined as an array of objects.
Is JSON the same as a JavaScript object?
No. JSON is a text format inspired by JavaScript object syntax, but it is stricter: keys must be double-quoted strings, values are limited to the six JSON types, and functions, undefined, comments, and trailing commas are not allowed. A JavaScript object lives in memory; JSON is a string you can save to a file or send over a network.
Ready to work with JSON? Clean up and check your data with the JSON Formatter and Validator, then reshape it with JSON to CSV, CSV to JSON, JSON to YAML, or XML to JSON.