What Is JSON? A Complete Developer's Guide
JSON (JavaScript Object Notation) is the most widely used data interchange format on the web. It powers the APIs behind every major platform — Twitter, GitHub, Stripe, Google Maps — and is the default language of modern web services. If you build or consume any kind of API, you work with JSON every day.
Despite its ubiquity, JSON has several rules that trip up developers, especially when coming from languages with looser syntax. This guide covers everything you need to know: structure, types, common errors, validation, and practical usage.
JSON Structure and Syntax Rules
A JSON document is always a single value — typically an object (key-value pairs in curly braces) or an array (ordered list in square brackets). Every JSON document must follow these rules precisely:
- All keys must be double-quoted strings — single quotes are invalid
- The last item in an object or array must not have a trailing comma
- String values must be in double quotes
- Comments are not allowed in standard JSON
- Numbers cannot start with a leading zero (except
0.xdecimals)
{
"name": "Alice",
"age": 30,
"active": true,
"score": 98.5,
"nickname": null,
"roles": ["admin", "editor"],
"address": {
"city": "London",
"country": "UK"
}
}
The Six JSON Data Types
1. String
A sequence of Unicode characters in double quotes. Special characters must be escaped with a backslash: "Hello\nWorld", "Tab:\there", "Quote:\"here\"". JSON strings support the full Unicode character set.
2. Number
Integer or floating-point, without quotes: 42, 3.14, -7, 1.5e10. JSON does not support NaN, Infinity, or -Infinity — these must be represented as null or a string.
3. Boolean
Exactly true or false — always lowercase. True, TRUE, yes, and 1 are all invalid JSON booleans.
4. Null
Represents an absent or empty value: null. Always lowercase. undefined (a JavaScript concept) is not valid JSON.
5. Object
An unordered set of key-value pairs wrapped in curly braces. Keys must be unique strings. Nested objects can be arbitrarily deep: {"user": {"profile": {"avatar": "url"}}}.
6. Array
An ordered list of values in square brackets. Arrays can contain mixed types: [1, "two", true, null, {"key": "val"}].
Common JSON Errors and How to Fix Them
Single Quotes Instead of Double Quotes
// Invalid JSON
{'name': 'Alice', 'age': 30}
// Valid JSON
{"name": "Alice", "age": 30}
Trailing Comma
// Invalid — trailing comma after last item
{"name": "Alice", "age": 30,}
// Valid
{"name": "Alice", "age": 30}
Unquoted Keys
// Invalid — JavaScript object literal, not JSON
{name: "Alice", age: 30}
// Valid JSON
{"name": "Alice", "age": 30}
Comments
// Invalid — JSON does not support comments
{
// User profile
"name": "Alice"
}
// Valid — remove the comment
{"name": "Alice"}
Validating and Fixing JSON Automatically
Hunting down JSON errors by hand is tedious and error-prone, especially in large payloads. The JSON validator on DataConvertProTools identifies every error with precise descriptions and locations. The Auto-Fix feature repairs common issues automatically:
- Replaces single quotes with double quotes
- Removes trailing commas
- Quotes unquoted keys
- Replaces
undefinedandNaNwithnull - Removes JavaScript-style comments
Paste your broken JSON, click Auto-Fix, and get valid, formatted output in seconds.
JSON in Real-World Development
REST APIs
JSON is the universal language of REST APIs. When you call an API with fetch() in JavaScript:
const response = await fetch('https://api.example.com/users/1');
const user = await response.json(); // Parses JSON automatically
console.log(user.name);
Configuration Files
The JavaScript ecosystem uses JSON extensively: package.json (npm), tsconfig.json (TypeScript), .eslintrc.json, launch.json (VS Code). These files configure tools and build systems.
Databases
MongoDB stores documents in BSON (Binary JSON). PostgreSQL has a native jsonb column type with full indexing support. Many SQL databases now support JSON functions for working with semi-structured data.
Converting JSON to Other Formats
Sometimes you need JSON data in a different format — XML for legacy system integration, CSV for spreadsheet import, or YAML for configuration files. Use the free JSON converter on DataConvertProTools to transform JSON to XML, YAML, or CSV with one click.
Validate, format, and convert your JSON instantly: DataConvertProTools JSON tools — validator, auto-fixer, prettifier, minifier, and converter for JSON, XML, YAML, and CSV. Free, private, no signup.