iLoveConverter
Categories 11 categories
Data JSON

The JSON (.json) Format, Explained

iLoveConverter Team 3 min read

On this page

JSON — JavaScript Object Notation — is the data language of the web. APIs speak JSON, configuration files use JSON, and almost every modern language has a built-in JSON parser. It is not “better XML” — it is simpler, with a small fixed grammar: objects, arrays, strings, numbers, booleans, null. That simplicity is both JSON’s strength (easy to generate and parse) and its weakness (no date type, no standard for comments, no schema enforcement by default).

The grammar

JSON has exactly seven value types:

TypeExampleNotes
Object{"key": "value"}Unordered map of string keys to values
Array[1, 2, 3]Ordered list of values
String"hello"Double-quoted, Unicode, escape with \", \\, \n, \t, \uXXXX
Number42, 3.14, -1e10IEEE 754 double; no distinction between int and float
Booleantrue, falseLowercase
NullnullLowercase

No dates, no binary, no comments, no trailing commas.

A valid JSON document is either an object or an array at the top level.

JSON.parse and friends

Parsing is straightforward because JSON grammar is unambiguous. Every language’s implementation uses a recursive descent parser. Pitfalls exist:

  • Numbers — JSON has only one number type. Large integers (> 2⁵³) lose precision when parsed as JavaScript numbers. Use BigInt or parse as string then validate.
  • Dates — ISO 8601 strings (2026-11-24T12:00:00Z) are conventional but not built-in. You must interpret them as dates yourself.
  • NaN, Infinity, -Infinity — NOT valid JSON. JavaScript’s JSON.stringify drops them or converts them to null.
  • Undefined — NOT valid JSON. Dropped from objects, converts to null in arrays.

JSON Schema and validation

JSON Schema (draft 2020-12 is current) adds the missing type system. A schema file validates JSON documents:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": ["name", "email"],
  "properties": {
    "name": { "type": "string", "minLength": 1 },
    "email": { "type": "string", "format": "email" },
    "age": { "type": "integer", "minimum": 0 }
  }
}

Languages like Python (jsonschema), TypeScript (zod), and Java (everit) all have validators.

Converting JSON

# Pretty-print:
jq '.' input.json > pretty.json

# JSON to CSV:
jq -r '.[] | [.name, .email, .score] | @csv' input.json > output.csv

# JSON to Parquet (Python):
python3 -c "import pandas as pd; df = pd.read_json('input.json'); df.to_parquet('output.parquet')"

# Validate against schema:
ajv validate -s schema.json -d input.json

Variants and extensions

  • JSONL (NDJSON) — one JSON value per line, great for streaming logs and data pipelines.
  • GeoJSON — JSON with Feature, FeatureCollection, and geometry types.
  • JSONB — PostgreSQL’s binary JSON storage, indexed for fast queries.
  • JSON5 — comments, trailing commas, single-quoted strings (used by Babel, TypeScript configs). NOT standard JSON.
  • MiniJSON / UBJSON / CBOR — binary JSON alternatives; not directly compatible but conceptually related.

Common problems

  • Large file memory blowup — JSON parsers load the whole document. Use JSONL or a streaming parser (ijson in Python) for gigabyte-sized data.
  • Trailing commas — invalid JSON; common in handwritten configs. Use a linter or JSON5.
  • Comment stripping — some tools accept comments but strip them silently; round-trip loses them.
  • Key ordering — JSON objects are unordered per spec. Implementations vary; do not rely on key order.

FAQ

JSON vs XML — why did JSON win?

JSON is simpler to generate, parse, and read. No closing tags, no namespace complexity, no prolog overhead. For APIs and config, JSON is unambiguously better. XML still dominates in document-oriented formats (DOCX, EPUB, SVG).

Is JSON slower than binary formats?

Usually yes, but for most APIs the difference is negligible compared to network latency. Use Protocol Buffers, FlatBuffers, or MessagePack only when bandwidth or CPU matters.

Why no comments in JSON?

To keep parsers simple. If you need comments, use JSON5 (JavaScript configs) or YAML (more popular for general configs). Never invent your own JSON-with-comments format.

Can I store binary data in JSON?

Yes, via Base64 encoding. This inflates size ~33%, so for large binaries consider a binary envelope (multipart upload) or a separate file. JSON is text-only.

Try it yourself — free, right in your browser

Everything mentioned in this guide runs locally on this site: no upload, no watermark, no sign-up.

Format deep-dives: JSON (.json) , CSV (.csv) , Parquet (.parquet.pq) , XML (.xml) , YAML (.yml.yaml)