JSON Formatting, Explained

By Udit Agarwal · Updated October 13, 2026

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:

  • It's minimal — almost no syntax to learn.
  • It maps cleanly onto data structures every language already has: objects/maps and arrays/lists.
  • It's human-readable and easy to diff in version control.

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

  • REST API requests and responses
  • Config files — package.json, tsconfig.json, CI pipelines
  • Structured logs — one JSON object per log line
  • NoSQL databases — MongoDB documents are JSON-like (BSON)
  • Browser storage — localStorage values are serialized JSON

JSON syntax and data types

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

  • Object — an unordered set of "key": value pairs wrapped in { }. Keys must be double-quoted strings.
  • Array — an ordered list of values wrapped in [ ].

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:

  • Beautify (pretty-print) adds indentation and line breaks so structure is easy to read and review. Use it while debugging, in code review, and in docs.
  • Minify strips every optional space and newline to produce the smallest possible payload. Use it for network responses and storage, where bytes matter.
  • Sort keys orders object keys alphabetically, which makes two documents directly comparable and produces clean, deterministic diffs.

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:

  • Strings and keys use double quotes, never single quotes.
  • No trailing commas after the last item in an object or array.
  • No comments (// or /* */).
  • No unquoted keys and no JavaScript expressions.

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:

  • JSONC — JSON with comments (used by VS Code config).
  • JSON5 — adds comments, trailing commas, unquoted keys, and single quotes.
  • NDJSON / JSON Lines — one independent JSON object per line, ideal for logs and streaming large datasets.

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

  • Use UTF-8 without a BOM.
  • Store dates as ISO 8601 strings ("2026-06-25T10:00:00Z").
  • Keep key casing consistent (pick camelCase or snake_case).
  • Never build JSON with string concatenation — serialize with your language's library.
  • Never run eval() on JSON; always use a real parser like JSON.parse.
  • Validate JSON at every trust boundary (API input, file import).

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 フォーマッター

More guides

All JSON tools · All guides