JSON (JavaScript Object Notation) is the universal language of web APIs. Whether you are building a web app, calling a REST API, or writing a configuration file, you will work with JSON constantly. This guide covers everything from basic syntax to debugging common errors.
Try it free — no signup required
JSON Formatter & Validator
JSON Syntax Rules
JSON has strict syntax requirements — a single missing comma or extra bracket will break everything.
{
"name": "Pradeep",
"age": 42,
"active": true,
"score": null,
"tags": ["developer", "devops"],
"address": {
"city": "Stockholm",
"country": "Sweden"
}
}- Keys must be double-quoted strings — single quotes are not valid JSON
- String values must use double quotes
- No trailing commas after the last item in an object or array
- No comments — JSON does not support
// comments - Numbers, booleans (
true/false), andnullare unquoted
Formatting vs Minifying
Formatted (pretty-printed)
Indented with spaces or tabs for human readability. Use when debugging or reading API responses.
Minified
All whitespace removed. Used in production to reduce file size and improve transfer speeds. A minified JSON file can be 20–40% smaller.
// Formatted (28 bytes)
{
"name": "Alice"
}
// Minified (16 bytes)
{"name":"Alice"}Common JSON Errors and How to Fix Them
Trailing comma
// INVALID — trailing comma after last item
{
"name": "Alice",
"age": 30, ← remove this comma
}
// VALID
{
"name": "Alice",
"age": 30
}Single quotes
// INVALID
{'name': 'Alice'}
// VALID
{"name": "Alice"}Unquoted keys
// INVALID (JavaScript object notation, not JSON)
{name: "Alice"}
// VALID
{"name": "Alice"}Parsing JSON in Code
JavaScript
const jsonString = '{"name": "Alice", "age": 30}';
const obj = JSON.parse(jsonString);
console.log(obj.name); // → "Alice"
// Convert back to JSON string
const str = JSON.stringify(obj, null, 2); // null, 2 = pretty printPython
import json
json_string = '{"name": "Alice", "age": 30}'
data = json.loads(json_string)
print(data["name"]) # → Alice
# Convert back
formatted = json.dumps(data, indent=2)Use the EazyTools JSON Formatter to instantly validate, format, and minify JSON — it highlights syntax errors with the exact line and character position.
Try it free — no signup required
JSON Formatter & Validator