What Is JSON and How to Work With It
Complete guide to JSON — syntax, common errors, formatting, minifying and converting to plain text.
What Is JSON?
JSON (JavaScript Object Notation) is a lightweight data-interchange format created by Douglas Crockford in the early 2000s. It is based on a subset of JavaScript syntax but is language-independent — Python, PHP, Java, Go, Ruby and every modern programming language can read and produce it natively.
Until the mid-2000s, XML dominated data exchange between systems. JSON prevailed because it is dramatically more compact, human-readable and directly parseable in JavaScript without an extra parser. Today it is the de facto language of REST APIs, configuration files and NoSQL data stores such as MongoDB.
Complete JSON Syntax
JSON has exactly six value types. Nothing more — this simplicity is precisely its power.
Object — {}
A collection of key: value pairs. Keys must be strings in double quotes.
{
"domain": "example.com",
"active": true,
"port": 443
}
Array — []
An ordered list of values of any type, including other objects or arrays.
{
"nameservers": ["ns1.example.com", "ns2.example.com"],
"ports": [80, 443, 8080]
}
String, Number, Boolean, Null
{
"issuer": "Let's Encrypt",
"ttl": 3600,
"dnssec": false,
"expiry": null
}
Strings use double quotes only. Numbers are written without quotes. Booleans are true/false (lowercase). null represents an absent or unknown value.
Nested Objects
One of JSON's most powerful features: objects inside objects at any depth.
{
"ssl": {
"issuer": "Let's Encrypt",
"valid": true,
"san": ["example.com", "www.example.com"]
},
"dns": {
"a": ["1.2.3.4"],
"mx": [{ "host": "mail.example.com", "priority": 10 }]
}
}
Formatting: Pretty-Print vs Minify
The same JSON can be represented in two ways:
| Format | Characteristic | When to use |
|---|---|---|
| Pretty-print 2 spaces | Compact, readable | Config files, source code, APIs in development |
| Pretty-print 4 spaces | More spacious, easier for deep nesting | Documentation, tutorials, human-read files |
| Minified | No whitespace or line breaks | HTTP responses, storage, bandwidth optimisation |
Example of the same data minified:
{"domain":"example.com","active":true,"port":443}
And pretty-printed with 2 spaces — identical content, completely different readability:
{
"domain": "example.com",
"active": true,
"port": 443
}
Plain Text Mode and Dot Notation
Deeply nested JSON is hard to scan visually, especially in API responses with dozens of fields. The JSON Viewer's Plain Text mode converts every value to one line using dot notation — the same convention used by JavaScript, Python and many query languages.
The nested example above becomes:
ssl.issuer = Let's Encrypt ssl.valid = true ssl.san[0] = example.com ssl.san[1] = www.example.com dns.a[0] = 1.2.3.4 dns.mx[0].host = mail.example.com dns.mx[0].priority = 10
This lets you immediately see which path leads to which value — useful when writing code to access the data or when comparing two API responses side by side.
Paste any JSON for instant formatting, validation and Plain Text mode:
→ JSON ViewerCommon JSON Mistakes
JSON is strictly typed — a single error makes the entire document invalid. These are the most frequent pitfalls:
Trailing Comma
The most common mistake — a comma after the last element. Allowed in JavaScript but not in JSON.
// Wrong
{
"host": "example.com",
"port": 443,
}
// Correct
{
"host": "example.com",
"port": 443
}
Single Quotes
Strings and keys require exclusively double quotes.
// Wrong
{ 'domain': 'example.com' }
// Correct
{ "domain": "example.com" }
Unquoted Keys
JavaScript object literals allow unquoted keys. JSON does not.
// Wrong (JavaScript object, not JSON)
{ domain: "example.com", port: 443 }
// Correct
{ "domain": "example.com", "port": 443 }
Comments
JSON does not support comments — neither // nor /* */. If you need comments in config files, consider JSONC or YAML instead.
// Wrong
{
// primary server
"host": "example.com"
}
// Correct — no comments
{
"host": "example.com"
}
NaN and Infinity
Values that exist in JavaScript but are not valid JSON. Use null or a numeric fallback.
// Wrong
{ "ratio": NaN, "score": Infinity }
// Correct
{ "ratio": null, "score": 9999 }
JSON Structure Metrics
| Metric | What it measures | Practical meaning |
|---|---|---|
| Depth | Maximum nesting level | Depth > 5–6 suggests an overly complex structure |
| Keys | Total number of keys | Indicator of schema complexity |
| Size | Size in bytes (raw / formatted) | Important for API responses and mobile clients |