JSON Formatting, Explained

JSON is the lingua franca of modern APIs, configuration files, and logs. Most developers read and write it every day, yet a single misplaced comma can break an entire payload. This guide explains what JSON actually is, the exact rules its syntax follows, the data types it supports, how formatting and validation fit into a real workflow, and the mistakes that trip people up most often.

What is JSON?

JSON (JavaScript Object Notation) is a lightweight, text-based format for storing and exchanging structured data. It was popularised by Douglas Crockford in the early 2000s and is now codified by two standards — ECMA-404 and RFC 8259 — which agree on exactly what counts as valid JSON.

Although it grew out of JavaScript object literals, JSON is completely language-independent: virtually every programming language can read and write it. Its official media type is application/json and files use the .json extension.

JSON won out over heavier formats like XML for a few reasons:

A JSON document is just text. A program turns that text into in-memory data by parsing it (e.g. JSON.parse), and turns data back into text by serializing it (e.g. JSON.stringify).

Where you'll meet JSON

JSON syntax and data types

JSON is built from two structures and a small set of value types.

A value is exactly one of:

Type Example Notes
String "hello" Double quotes only; supports escapes like \n, \t, \", \\, \uXXXX
Number 42, -3.14, 6.02e23 No NaN, Infinity, leading zeros, or + sign
Boolean true, false Lowercase only
Null null Lowercase only
Object { "id": 1 } Keys are strings; duplicate keys are discouraged
Array [1, "two", true] May mix value types

Whitespace between tokens is insignificant — that's exactly why a formatter can add or remove it freely. A small but complete example:

{
  "name": "Ada",
  "active": true,
  "roles": ["admin", "editor"],
  "profile": { "age": 36, "city": "London" },
  "scores": [98.5, 87, 91],
  "deletedAt": null
}

A note on numbers

JSON numbers are typically parsed into IEEE-754 doubles. Integers larger than 2^53 (e.g. 64-bit IDs or Twitter/X snowflake IDs) can silently lose precision. The common fix is to transmit them as strings: "id": "9007199254740993".

Beautify, minify, and sort

The same JSON can be written several ways without changing the data:

None of these change the underlying data — only its presentation. A formatter simply parses the JSON and re-serializes it with (or without) whitespace.

Validating JSON and JSON Schema

JSON is strict, and that strictness is a feature: a validator can tell you exactly where a document breaks, usually by line and column. The core syntax rules are:

Syntax validation answers "is this well-formed JSON?". A separate tool, JSON Schema, answers a deeper question — "does this JSON have the shape I expect?" — by declaring required fields, types, and value constraints. Schema validation is worth adding at trust boundaries like API inputs.

Common JSON errors and how to fix them

Problem Fix
Unexpected token on valid-looking JSON Check the reported line for a trailing comma, single quote, or unquoted key.
Pasted a JavaScript object, not JSON Quote every key and string value; remove comments and trailing commas.
NaN, Infinity, or undefined in output JSON supports none of these — use a number or null.
Large IDs change value after a round trip Transmit big integers as strings to avoid double-precision loss.
Duplicate keys Most parsers keep only the last — remove duplicates.
Garbled first character / parse fails at position 0 A UTF-8 BOM or copied whitespace is at the start — strip it.
API "works in browser, fails in code" Confirm the response Content-Type is application/json and the body is actually JSON, not HTML.

JSON, JSON5, JSONC, and NDJSON

Several "JSON-ish" formats relax the rules — useful, but not interchangeable with strict JSON:

If a strict parser rejects your file, it may be one of these variants.

JSON vs. XML and YAML

JSON XML YAML
Verbosity Low High Lowest
Comments No Yes Yes
Data types Built-in Text + schema Built-in
Best for APIs, configs Documents, SOAP Human-edited config

Best practices

Format, validate, and minify JSON online

The JSON Formatter does all of this in one place: paste raw JSON to pretty-print it with your chosen indentation, collapse it to a single line, sort keys, or catch syntax errors with their exact location. Everything runs in your browser, so the data you paste never leaves your device.

Frequently asked questions

Is JSON case-sensitive? Yes. "Name" and "name" are different keys, and true/null must be lowercase.

Can JSON have comments? No — strict JSON forbids them. Use JSONC or JSON5 for config files that need comments.

Does beautifying or minifying change my data? No. Only whitespace changes; every key and value stays identical.

Why does my large number lose precision? JSON numbers are parsed as 64-bit floats. Integers above 2^53 should be sent as strings.

Is my JSON uploaded anywhere? No. The JSON Formatter runs entirely in your browser, so nothing is sent to a server.

Keep going

JSON-Formatierer