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:

FormatCharacteristicWhen to use
Pretty-print 2 spacesCompact, readableConfig files, source code, APIs in development
Pretty-print 4 spacesMore spacious, easier for deep nestingDocumentation, tutorials, human-read files
MinifiedNo whitespace or line breaksHTTP 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 Viewer

Common 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

MetricWhat it measuresPractical meaning
DepthMaximum nesting levelDepth > 5–6 suggests an overly complex structure
KeysTotal number of keysIndicator of schema complexity
SizeSize in bytes (raw / formatted)Important for API responses and mobile clients

Frequently Asked Questions

Why does a trailing comma break my JSON when it works fine in JavaScript?
JavaScript (ES5+) allows trailing commas in arrays and objects for editing convenience. JSON, however, strictly follows RFC 8259 which does not permit them. JSON.parse() and all JSON parsers will throw a SyntaxError. You must remove the comma after the last element.
What is the difference between a JSON object and a JavaScript object literal?
A JavaScript object literal is code syntax: it allows single quotes, unquoted keys, trailing commas, comments, functions and undefined values. JSON is a data format: exclusively double-quoted strings, no comments, no functions — only the six basic types. Every valid JSON is a valid JavaScript object, but the reverse is not always true.
What does the "depth" metric in the JSON Viewer mean?
Depth counts how many levels of nesting your structure has. Depth 1 means a flat object; depth 3 means objects inside objects inside objects. Values above 5–6 usually signal a design issue — very deeply nested structures are harder to read, maintain and serialise.
Is the data I paste into the JSON Viewer stored anywhere?
No. Processing happens entirely in your browser — nothing is sent to a server and no data is stored. You can safely paste API responses, configuration files or any data you want to inspect.

Try it now

Related guides