What is JSON? A Complete Guide for Developers
JSON — JavaScript Object Notation — is the lingua franca of data exchange on the modern web. It powers REST APIs, configuration files, NoSQL databases, and inter-service communication in virtually every tech stack. Despite its name, JSON is language-agnostic: parsers exist for Python, Ruby, Go, Java, C#, PHP, and dozens of other languages. Understanding JSON thoroughly makes you a more effective developer across every discipline.
JSON Syntax
JSON is built on two data structures: an ordered list (array) and a collection of name/value pairs (object). The entire specification fits on a single page, which is a big part of its appeal over earlier formats like XML.
A JSON document is a single value — either an object, an array, a string, a number, a boolean, or null. Objects are wrapped in curly braces {} and contain comma-separated key/value pairs where keys are always double-quoted strings. Arrays are wrapped in square brackets [] and contain comma-separated values.
{
"name": "Alice",
"age": 30,
"active": true,
"scores": [98, 87, 92],
"address": {
"city": "London",
"zip": "EC1A 1BB"
},
"nickname": null
}
JSON Data Types
JSON supports exactly six data types, and knowing their rules prevents countless bugs:
- String — a sequence of Unicode characters wrapped in double quotes. Escape special characters with a backslash:
",\,\/,,,\uXXXX. - Number — integer or floating-point. No distinction between the two in the spec. Avoid leading zeros; scientific notation (
1.5e10) is valid. - Boolean — exactly
trueorfalse, lowercase.TrueandFalseare not valid. - Null — exactly
null, lowercase, representing the intentional absence of a value. - Array — an ordered list of values of any type, including mixed types.
- Object — an unordered set of key/value pairs. Key order is not guaranteed by the spec, though most parsers preserve insertion order in practice.
"2026-03-28T12:00:00Z") or as Unix timestamps (integers).Valid vs Invalid JSON Examples
Because JSON has strict syntax rules, small mistakes cause parse errors. Here are the most common traps:
// INVALID — trailing comma
{ "a": 1, "b": 2, }
// INVALID — single-quoted string
{ 'name': 'Alice' }
// INVALID — unquoted key
{ name: "Alice" }
// INVALID — comment (JSON has no comment syntax)
{ "port": 8080 // default port }
// VALID
{ "a": 1, "b": 2 }
JSON in REST APIs
REST APIs overwhelmingly use JSON as their request and response body format. When a client sends a POST request, it sets the Content-Type: application/json header and sends a JSON body. The server responds with Content-Type: application/json and a JSON payload.
// Request body
POST /api/users
Content-Type: application/json
{ "username": "alice", "email": "[email protected]" }
// Response body
HTTP/1.1 201 Created
Content-Type: application/json
{ "id": 42, "username": "alice", "created_at": "2026-03-28T09:00:00Z" }
Most HTTP client libraries handle JSON serialisation and deserialisation automatically. In JavaScript, JSON.stringify() serialises objects and JSON.parse() deserialises strings. In Python, the json module provides json.dumps() and json.loads().
JSON in Configuration Files
Many tools use JSON for their configuration: package.json in Node.js, tsconfig.json in TypeScript, manifest.json in Chrome extensions, and appsettings.json in .NET. Its strict syntax and universal parser support make it a reliable choice for machine-written config, though the lack of comments is a persistent complaint (leading many teams to choose YAML instead for human-authored config).
Common JSON Mistakes
Beyond syntax errors, there are semantic mistakes that bite developers repeatedly:
- Assuming key order — the JSON spec does not guarantee object key order. Don't write code that depends on it.
- Large integers — JavaScript's
Numbertype is a 64-bit float, so integers larger than 253 lose precision. Use strings for large IDs (Twitter's API famously does this). - Deeply nested structures — most parsers have recursion limits. Extremely deep nesting can cause stack overflows.
- NaN and Infinity — these are valid JavaScript values but are not valid JSON. Attempting to serialise them produces
nullor throws an error depending on the language.
Tools for Working with JSON
The JSON Formatter & Validator at Tools.Fun lets you paste any JSON string and instantly validates it, highlights syntax errors, and pretty-prints the result with collapsible tree navigation. It's the fastest way to debug malformed API responses or inspect deeply nested payloads — no install, no login, runs entirely in your browser.
For schema validation, JSON Schema lets you define the expected shape of a JSON document and validate instances against it. Tools like Ajv (JavaScript) and jsonschema (Python) implement the spec and are widely used in API testing pipelines.