JSON, NDJSON (JSON Lines) and YAML all represent the same underlying data model: objects (key–value maps), arrays (ordered lists), strings, numbers, booleans and null. Yet choosing the wrong one for a job — or converting carelessly between them — causes some of the most puzzling bugs in software engineering: a 2 GB export that crashes a server’s memory, a CI pipeline that tests Python 3.1 instead of 3.10, or a customer in Norway (NO) whose country code turns into the boolean false.

This guide compares how the three formats work, when to use each one, and how to convert between them without losing a single digit or character.

Top: three cards comparing JSON, NDJSON and YAML syntax and use cases. Bottom: four silent YAML traps when strings are unquoted — country: NO becomes false, zip: 02134 becomes octal 1116, python: 3.10 becomes 3.1, and 64-bit integer IDs get rounded.
The same data in JSON, NDJSON and YAML — and the four values that silently change when YAML guesses at unquoted strings.

The same dataset in all three formats

Suppose we have two records describing regional service configurations:

1. Standard JSON (.json)

[
  {
    "account_id": 9007199254740993,
    "country": "NO",
    "postal_code": "02134",
    "version": "3.10",
    "feature_flag": "off",
    "enabled": true
  },
  {
    "account_id": 9007199254740994,
    "country": "GB",
    "postal_code": "SW1A 1AA",
    "version": "3.12",
    "feature_flag": "on",
    "enabled": false
  }
]

In JSON, every key and every string value is wrapped in double quotes ("…"). There is no ambiguity between the string "false" and the boolean false, or between the string "3.10" and the number 3.1.

2. NDJSON / JSON Lines (.jsonl or .ndjson)

{"account_id":9007199254740993,"country":"NO","postal_code":"02134","version":"3.10","feature_flag":"off","enabled":true}
{"account_id":9007199254740994,"country":"GB","postal_code":"SW1A 1AA","version":"3.12","feature_flag":"on","enabled":false}

NDJSON (Newline-Delimited JSON, also standardised at jsonlines.org) removes the outer [ … ] brackets and the commas between records, and writes each record as one compact JSON value on its own line. Every individual line is valid JSON on its own.

3. YAML (.yaml or .yml)

- account_id: 9007199254740993
  country: "NO"
  postal_code: "02134"
  version: "3.10"
  feature_flag: "off"
  enabled: true
- account_id: 9007199254740994
  country: GB
  postal_code: SW1A 1AA
  version: "3.12"
  feature_flag: "on"
  enabled: false

YAML replaces braces and brackets with indentation and leading dashes (-), allows inline # comments, and lets you omit quotes around ordinary strings like GB or SW1A 1AA. Notice, however, that "NO", "02134", "3.10" and "off" kept their quotes above. Removing those quotes triggers the four classic YAML bugs explained below.

Why NDJSON exists: the problem with huge JSON arrays

A standard JSON array ([ {...}, {...} ]) is a single value. To validate or parse it with JSON.parse(), a program normally has to read the entire file from the opening [ to the closing ] at the very end.

That design works well for a 50 KB API response, and poorly for a 5 GB log archive or database export:

  1. Memory consumption. Loading a 2 GB JSON array into memory in Node.js or a browser tab creates millions of objects at once and usually hits the heap limit before finishing.
  2. Appending new records is expensive. You cannot simply append a new record to the end of a .json array file without seeking backward, deleting the closing ], adding a comma, writing the new object, and writing ] again.
  3. One bad record ruins the whole file. If a process crashes while writing record 999,999, the closing ] is missing and the entire file is syntactically invalid JSON.

NDJSON solves all three problems. Because each line is an independent JSON object separated by \n:

  • A reader can stream the file one line at a time in constant memory.
  • A logger or data pipeline can append a new record with a single write(line + "\n").
  • Standard Unix tools work directly on the file: wc -l events.jsonl counts records, head -n 100 events.jsonl takes a valid 100-record sample, and grep filters records without a specialised parser.
  • If one line is corrupted, the other 999,999 lines can still be parsed and the error message can point to the exact line number.

For those reasons, BigQuery, ClickHouse, DuckDB, Snowflake, Elasticsearch and LLM fine-tuning / batch APIs (OpenAI, Anthropic, Vertex AI) all use .jsonl as their primary JSON ingestion format.

YAML was designed for files that humans read and edit by hand: Kubernetes manifests, Docker Compose files, GitHub Actions workflows, Ansible playbooks and application configuration files. For hand-edited files, YAML has two real advantages over JSON:

  1. Comments (#). You can document why a timeout is set to 30 seconds or why a feature flag exists. JSON has no comments.
  2. Less visual noise. Without braces, commas and quotes on every key, diffs in pull requests are easier to read.

The price of that convenience is implicit typing. Because YAML does not require quotes around strings, every YAML parser must look at an unquoted value and guess whether you meant a string, a boolean, a number, a date or null.

Trap 1: The “Norway problem” (country: NO → false)

In YAML 1.1 — which is still implemented by Python’s default PyYAML loader, many Ruby/Java tools and older Kubernetes utilities — the boolean type accepts 22 different unquoted words:

y, Y, yes, Yes, YES, n, N, no, No, NO,
true, True, TRUE, false, False, FALSE,
on, On, ON, off, Off, OFF

When a list of two-letter ISO 3166-1 country codes is written to YAML without quotes:

countries:
  - SE
  - DK
  - NO   # Norway!
  - FI

A YAML 1.1 parser reads that list as ["SE", "DK", false, "FI"]. The same bug hits feature flags (feature: off → false), confirmation prompts (answer: y → true) and compass directions (heading: N → false).

Even in YAML 1.2 (which narrowed unquoted booleans to true/false in the core schema), many parsers keep YAML 1.1 compatibility enabled or convert null and ~ to null.

Trap 2: Leading zeros and octal numbers (zip: 02134 → 1116)

In YAML 1.1, an unquoted integer that starts with 0 and contains only the digits 0–7 is interpreted as an octal (base-8) number. Boston’s ZIP code 02134 contains only digits below 8, so:

# YAML 1.1 reads 02134 in base 8:
# (2 × 512) + (1 × 64) + (3 × 8) + 4 = 1116
postal_code: 02134   # → 1116

Meanwhile, a ZIP code next door with an 8 or 9 in it (02138) cannot be octal, so some parsers treat it as decimal 2138 (dropping the leading zero) or a string. In YAML 1.2, 02134 is parsed as the decimal integer 2134 — still losing the leading zero!

Trap 3: Version numbers and trailing zeros (python: 3.10 → 3.1)

Anyone who has configured a GitHub Actions or CI matrix for Python 3.10 or Node 20.10 has met this bug:

# Broken: 3.10 is parsed as the floating-point number 3.1
python-version: [3.8, 3.9, 3.10]

Because 3.10 is not in quotes, the YAML parser turns it into the number 3.1, and the CI runner downloads Python 3.1 instead of Python 3.10. Version numbers, prices (19.50) and measurements with significant trailing zeros must always be quoted ("3.10").

Trap 4: Unquoted colons and timestamps (12:30 → 750)

In YAML 1.1, sexagesimal (base-60) numbers are supported for time and angles: unquoted 12:30 becomes 12 × 60 + 30 = 750, and 1:00:00 becomes 3600. And if a value contains a colon followed by a space (note:Warning: check disk), YAML treats the second colon as a nested mapping key and fails with a syntax error.

Comparison summary: which format should you choose?

Question JSON (.json) NDJSON (.jsonl) YAML (.yaml)
Best for Web APIs, browser state, small/medium structured files Data warehouses, logs, streaming, LLM datasets Hand-edited configuration files, CI/CD, Kubernetes
Comments allowed? No No Yes (# comment)
Streaming / append-friendly? No (must close outer [...]) Yes (1 record per line) Awkward (indentation/documents)
Safe from silent type guessing? Yes (strings are always quoted) Yes (every line is strict JSON) Only when ambiguous strings are quoted
Whitespace sensitive? No (can minify to 1 line) Line breaks separate records Yes (spaces only; tabs forbidden)

Rule of thumb:

  • If machines write and read it over HTTP, use JSON.
  • If there are thousands or millions of records (or you want to stream, append or load into BigQuery / ClickHouse / DuckDB / AI tools), use NDJSON (.jsonl).
  • If humans maintain it in Git and need comments, use YAML — and quote strings that look like booleans, numbers, versions or dates.

Converting safely with RapidConvertor

RapidConvertor includes dedicated browser-based tools for all three formats:

  • JSON ⇄ YAML Converter: converts JSON to clean block YAML and automatically quotes every string that YAML 1.1 or 1.2 could misread ("NO", "off", "02134", "3.10", "2026-11-07"), telling you how many values it protected. Converting YAML back to JSON keeps 64-bit numbers exact.
  • NDJSON / JSON Lines Converter: converts JSON arrays (or CSV files) into .jsonl and converts .jsonl back into formatted JSON arrays, with exact line-by-line syntax validation.
  • JSON Formatter & Validator: pretty-prints, minifies and validates JSON while keeping 64-bit integers and high-precision decimals untouched.
  • CSV to JSON Converter: turns CSV spreadsheets into JSON while preserving leading zeros and long IDs by default.

All conversions run locally inside your browser tab — your configuration files and datasets never leave your device.