Example 1 — Simple object
{
"name": "John Doe",
"age": 30,
"city": "New York"
} 
This page is a self-contained introduction to JSON (JavaScript Object Notation)—the data format behind modern web APIs. You will understand what JSON is, read and write valid syntax, and use it in JavaScript.
Format overview.
Structured text.
Why it wins.
Objects & arrays.
APIs & config.
parse & stringify.
JSON (JavaScript Object Notation) is a lightweight data-interchange format that is easy for humans to read and write and easy for machines to parse and generate.
It is widely used for transmitting data between a server and a web application, as well as for storing configuration data in files like package.json, tsconfig.json, and API response payloads.
Whenever a website loads data without refreshing the whole page, JSON is often traveling between the browser and the server in the background.
JSON is a text-based format for representing structured data. It is based on a subset of JavaScript object literal syntax, but it is language-independent—Python, Java, PHP, Go, and virtually every modern language can read and write JSON.
Unlike binary formats, JSON is plain UTF-8 text. You can open a .json file in any editor, inspect API responses in DevTools, and debug data without special tools.
JSON has become the de facto standard for data interchange on the web:
JSON data is organized into key-value pairs, similar to objects in JavaScript. Here is a simple JSON object:
{
"name": "John Doe",
"age": 30,
"city": "New York"
} null{ }, with comma-separated key-value pairs[ ], with comma-separated valuesJSON appears across modern software development:
| Type | Example | Notes |
|---|---|---|
| String | "hello" | Must use double quotes |
| Number | 42, 3.14 | Integer or decimal |
| Boolean | true, false | Lowercase only |
| null | null | Empty or missing value |
| Array | [1, 2, 3] | Ordered list of values |
| Object | {"key": "value"} | Collection of key-value pairs |
| Task | Example |
|---|---|
| Object | {"id": 1, "active": true} |
| Array | ["red", "green", "blue"] |
| Nested | {"user": {"name": "Alex"}} |
| Parse (JS) | JSON.parse(text) |
| Stringify (JS) | JSON.stringify(obj) |
| Invalid | {name: "x"} — keys need quotes |
In JavaScript, converting between JSON text and usable objects is built in:
const jsonString = '{"name": "John Doe", "age": 30, "city": "New York"}';
const data = JSON.parse(jsonString);
console.log(data.name); // John Doe const obj = { name: "John Doe", age: 30, city: "New York" };
const jsonString = JSON.stringify(obj);
console.log(jsonString);
// {"name":"John Doe","age":30,"city":"New York"} JSON.parse() throws an error if the text is invalid JSON—always validate user-provided or external data before parsing.
Five JSON samples you can copy into the JSON Validator or use in JavaScript with JSON.parse().
{
"name": "John Doe",
"age": 30,
"city": "New York"
} ["red", "green", "blue"] {
"orderId": 1001,
"customer": {
"name": "Alex",
"email": "alex@example.com"
},
"items": [
{ "product": "Notebook", "qty": 2 },
{ "product": "Pen", "qty": 5 }
],
"paid": true
} const jsonString = '{"name": "John Doe", "age": 30, "city": "New York"}';
const data = JSON.parse(jsonString);
console.log(data.name); const obj = { name: "John Doe", age: 30, city: "New York" };
const jsonString = JSON.stringify(obj);
console.log(jsonString); | Format | Strengths | Common use today |
|---|---|---|
| JSON | Compact, maps to JS objects, fast to parse | REST APIs, config files, mobile apps |
| XML | Schema validation, attributes, mature tooling | Legacy enterprise systems, RSS, SOAP |
See the full comparison on the JSON vs XML tutorial page.
JavaScript calls an API with fetch or similar.
The response body is a JSON text string over HTTP.
response.json() or JSON.parse() turns text into objects.
Your app displays lists, charts, or forms using the parsed data.
JSON is a versatile and efficient format for representing and transmitting data on the web. Its simplicity, readability, and widespread support make it an essential tool for web developers.
By mastering JSON syntax and understanding its use cases, you can leverage its power to build robust and scalable web applications—from simple config files to global API ecosystems.
{ }, arrays [ ], strings, numbers, booleans, and null.JSON.parse() reads JSON; JSON.stringify() writes it.JSON.parse() in try/catch for untrusted inputuserId, not id1)undefined, or comments in JSONDouglas Crockford specified JSON in the early 2000s and chose a minimal syntax deliberately—no comments, no trailing commas, no ambiguity. Today JSON is defined by RFC 8259 and powers billions of API calls every day.
Copy any example into the JSON validator and check your syntax in one click.
10 people found this page helpful