What is JSON?
JSON (JavaScript Object Notation) is a lightweight data interchange format that's easy for humans to read and write, and easy for machines to parse and generate. It's the most common format for APIs and configuration files.
JSON Syntax Rules
- Data is in name/value pairs
- Data is separated by commas
- Curly braces hold objects
- Square brackets hold arrays
- String values must use double quotes (not single quotes)
- No trailing commas allowed
- No comments allowed in standard JSON
JSON Data Types
| Type | Example | Description |
|---|---|---|
string | "hello" | Text in double quotes |
number | 42, 3.14, -1 | Integer or floating point |
boolean | true, false | Lowercase only |
null | null | Empty/no value |
object | {"key": "value"} | Key-value pairs in braces |
array | [1, 2, 3] | Ordered list in brackets |
JSON Object Example
{
"name": "John Doe",
"age": 30,
"email": "john@example.com",
"isActive": true,
"address": {
"street": "123 Main St",
"city": "New York",
"zip": "10001"
},
"hobbies": ["reading", "gaming", "hiking"]
}Common JSON Mistakes
- Single quotes: Use
"string"not'string' - Trailing commas:
[1, 2, 3,]is invalid - Unquoted keys: Use
{"key": 1}not{key: 1} - Comments: JSON doesn't support
// comments - Undefined: Use
nullinstead ofundefined
JSON vs JavaScript Objects
JSON is a subset of JavaScript object syntax, but with stricter rules:
- JSON requires double quotes for strings and keys
- JSON doesn't allow functions, dates, or undefined
- JSON doesn't allow trailing commas
- JSON doesn't allow comments
JSON Schema Validation
JSON Schema is a vocabulary for validating JSON data. It lets you define the structure, types, and constraints for your JSON:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer", "minimum": 0 }
},
"required": ["name"]
}JSON Tools You'll Need
- JSON Formatter – Beautify messy JSON
- JSON Validator – Check for syntax errors
- JSON Diff – Compare two JSON objects
- JSON Minify – Compress JSON for production
- JSON to CSV – Export to spreadsheets