What is JSON? Beginner's Guide with Syntax, Examples
JSON is a text format for structured data. Learn the syntax rules, see an example, and find out how APIs use JSON and how to test it.
What is JSON?
JSON (JavaScript Object Notation) is a text format for structured data. It builds values from objects, arrays, strings, numbers, true, false and null. Any language can read and write it, people can read it too, and it is the default format for request and response bodies in web APIs. Its media type is application/json.
How JSON works
A JSON document is one value, usually an object. An object is a set of "key": value pairs in curly braces, an array is an ordered list in square brackets, and values can nest as deep as you need. The format is defined in RFC 8259, and MDN has a good beginner walkthrough.
{
"id": 42,
"name": "Alice Johnson",
"active": true,
"tags": ["admin", "beta-tester"],
"address": { "city": "Berlin", "zip": "10115" },
"last_login": "2026-10-01T14:30:00Z",
"avatar": null
}JSON has no date type, so dates travel as strings (ISO 8601 is the usual choice) and your code converts them.
Syntax rules that trip people up
- Keys and strings use double quotes. Single quotes are invalid.
- No trailing commas after the last item.
- No comments.
- No
undefined,NaNorInfinity. Usenullor leave the key out. - Numbers cannot have leading zeros.
- Text sent between systems must be UTF-8.
Every JSON document is a valid JavaScript literal, but not the other way round: a JavaScript object with unquoted keys or a trailing comma is not JSON.
Parsing and generating JSON
Turning text into data is called parsing (deserialization), and turning data into text is serialization. Every mainstream language ships this in its standard library:
// JavaScript
const data = JSON.parse('{"id": 42}');
const text = JSON.stringify({ id: 42 });
# Python
import json
data = json.loads('{"id": 42}')
text = json.dumps({"id": 42})To read a minified response by eye, paste it into the free JSON prettify tool and it comes back indented.
JSON in APIs
Most REST APIs exchange JSON. The client sets Content-Type: application/json on requests with a body, and the server answers with the same header. What sits in the body is the request or response payload, and the URL it goes to is the API endpoint.
POST /api/users HTTP/1.1
Content-Type: application/json
{ "email": "alice@example.com", "name": "Alice" }You can send this exact request from the command line with the online curl tool. JSON is also the message format of JSON-RPC, a protocol that calls remote methods instead of addressing resources.
Validating JSON
Valid syntax only means a parser can read the text. It does not mean the data is right. A JSON Schema describes which fields are required, which types they have and which values are allowed, so a validator can reject a payload that parses fine but has "age": "forty". Our step-by-step JSON Schema guide shows how to write one.
Common JSON mistakes
- Building JSON by string concatenation. One unescaped quote in a name breaks the document. Always serialize with a library.
- Forgetting the Content-Type header. Many servers then treat the body as plain text or form data and return a 400 or 415.
- Putting large integers in numbers. Some parsers, JavaScript included, lose precision on very large integers such as 64-bit IDs. Send them as strings.
- Relying on key order. Objects are unordered sets of members. Do not depend on a particular order.
- Changing field names or types without notice. A renamed field is a breaking change for every client that reads it.
JSON, testing and monitoring
JSON problems rarely show up as a crash. A 200 response can still carry an empty list or a missing field. When you test an API, assert on the body as well as the status code. LoadFocus API monitoring checks the status code, the response body, headers and response time on a schedule, with a check every 5 minutes on the free plan, so a broken payload raises an alert instead of waiting for a customer to find it.
FAQ: JSON
What does JSON stand for?
JSON stands for JavaScript Object Notation. It grew out of JavaScript object syntax, but it is a separate, language-independent format.
Is JSON a programming language?
No. JSON only describes data. It has no variables, functions or logic, so you need a programming language to produce and consume it.
What is the difference between JSON and a JavaScript object?
JSON is text, a JavaScript object lives in memory. JSON is stricter: keys need double quotes, comments and trailing commas are not allowed, and functions and undefined values cannot be represented.
Can JSON contain comments?
No. The standard has no comment syntax. If you need notes, use a separate documentation field or a format designed for configuration files.
Why do APIs use JSON instead of XML?
JSON is shorter, maps directly onto the objects and arrays of most programming languages, and needs less code to parse. XML is still the better choice when you need mixed text and markup, such as documents.
Related terms
- What is JSON-RPC? Protocol, Examples, REST Comparison
- What is multipart/form-data Content-Type? File Uploads, Examples
- What is Swagger? Swagger vs OpenAPI Explained
- CRUD Operations: Create, Read, Update, Delete Explained
- What Are API Attacks?
- What Are API Cookies? Definition and Security
- API Performance Metrics: Latency, Throughput, Error Rate
- What are Internal APIs?
Related LoadFocus Tools
Put this concept into practice with LoadFocus, the same platform that powers everything you just read about.