Getting Started with JSON: A Beginner's Guide
JSON (JavaScript Object Notation) is the most widely used data interchange format on the web. Every time a mobile app talks to a server, a frontend framework fetches data, or two microservices communicate, JSON is almost certainly the format they use. This comprehensive guide will take you from absolute beginner to confident JSON user.
What Is JSON?
JSON is a lightweight, text-based data format derived from JavaScript object literal syntax. It was popularized by Douglas Crockford in the early 2000s as a simpler alternative to XML. Today it is language-independent and supported natively by every major programming language. JSON's key design goals were simplicity, readability, and universality. Use our JSON Formatter to see how any JSON document is structured.
Complete JSON Syntax Reference
JSON syntax is strict but simple. Understanding every rule is essential:
- Objects are enclosed in curly braces
{}and contain comma-separated key-value pairs - Arrays are enclosed in square brackets
[]and contain comma-separated values - Keys must be double-quoted strings â no single quotes, no unquoted identifiers
- String values must be double-quoted â single quotes will cause a parse error
- Numbers can be integers or decimals (e.g.,
42,-3.14,1.5e10) â no leading zeros, no NaN, no Infinity - Booleans must be lowercase
trueorfalse - Null is represented as
nullâ noundefined, noNone - No trailing commas â the last element in an object or array must not be followed by a comma
- No comments â standard JSON does not support comments (use JSONC if needed)
The Six JSON Data Types Explained
| Type | Example | Rules | Common Pitfall |
|---|---|---|---|
| String | "Hello, World!" | Double quotes only, Unicode, escape sequences (\\n, \\t, \\\", \\\\, \\uXXXX) | Using single quotes or missing escape for special characters |
| Number | 42, 3.14, -1.5e-2 | Decimal integer or float, scientific notation, no octal/hex, no NaN/Infinity | Leading zeros (like 01) or using NaN |
| Boolean | true, false | Must be lowercase | Writing True or TRUE |
| Null | null | Represents empty or absent value | Using undefined (JS), None (Python), or nil |
| Array | [1, "two", null, true] | Ordered list, mixed types allowed, zero-indexed | Trailing comma after last element |
| Object | {"key": "value"} | Unordered key-value pairs, unique keys, nested objects allowed | Duplicate keys (parser takes last value) |
Complete JSON Example
{
"store": {
"name": "TechCorp",
"open": true,
"rating": 4.8,
"address": {
"street": "123 Main St",
"city": "San Francisco",
"zip": null
},
"products": [
{"id": 1, "name": "Laptop", "price": 1299.99, "inStock": true},
{"id": 2, "name": "Mouse", "price": 29.99, "inStock": false}
],
"tags": ["electronics", "computers"]
}
}
How to Validate JSON
Always validate your JSON before using it. Our JSON Validator provides instant syntax checking with detailed error messages that include line numbers, column positions, and the exact unexpected character. It catches trailing commas, missing quotes, unquoted keys, and bracket mismatches. For deeper analysis, use our JSON Linter which also checks naming conventions and key ordering.
How to Format JSON for Readability
Minified JSON is compact but unreadable. Our JSON Formatter adds proper indentation (configurable: 2-space, 4-space, or tabs), line breaks, and syntax highlighting. For interactive exploration, use our JSON Viewer which displays data as a collapsible tree with search functionality. Our JSON Tree Viewer goes further with expandable nodes and path highlighting.
Parsing JSON in Different Languages
JavaScript
const json = '{"name": "John", "age": 30}';
let obj;
try {
obj = JSON.parse(json);
console.log(obj.name); // John
} catch (e) {
console.error("Parse error:", e.message);
}
Python
import json
json_string = '{"name": "John", "age": 30}'
try:
data = json.loads(json_string)
print(data["name"]) # John
except json.JSONDecodeError as e:
print(f"Error at line {e.lineno}: {e.msg}")
Java (Jackson)
ObjectMapper mapper = new ObjectMapper();
try {
JsonNode node = mapper.readTree(jsonString);
System.out.println(node.get("name").asText());
} catch (JsonProcessingException e) {
System.err.println("Parse failed: " + e.getMessage());
}
Go
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
}
var p Person
err := json.Unmarshal([]byte(jsonString), &p)
if err != nil { log.Fatal(err) }
fmt.Println(p.Name)
JSON in the Real World: Common Use Cases
- REST APIs â Nearly every modern web API uses JSON for request and response bodies. Our JSON to cURL tool converts JSON payloads into curl commands for testing.
- Configuration files â package.json, tsconfig.json, .eslintrc.json, and Chrome extension manifests all use JSON.
- Databases â MongoDB stores BSON (Binary JSON). PostgreSQL and MySQL have native JSON column types. Our JSON to MongoDB converter helps migrate data.
- Data transfer â Microservices, IoT devices, and cloud functions exchange JSON messages. Our JSON to NDJSON tool helps with streaming scenarios.
- Machine learning â Training data, model configurations, and prediction outputs commonly use JSON format.
Common Mistakes to Avoid
Beginners frequently make these errors:
- Using single quotes or unquoted keys â always use double quotes
- Adding trailing commas â JSON does not allow them
- Writing comments â use JSONC or external documentation
- Mismatching brackets â every
{needs a}, every[needs a] - Using undefined values â use
nullinstead
Catch these automatically with our JSON Validator and fix them with JSON Repair.
Next Steps
Now that you understand JSON fundamentals, explore our complete suite of JSON tools to format, validate, convert, compress, and generate JSON data. Each tool is free, works entirely in your browser, and requires no registration.