NDJSON vs JSON: when one record per line wins
24 NOVEMBER 2026 · 7 MIN READ
NDJSON puts one complete JSON value on every line. That single change is what makes log shipping, bulk imports and incremental parsing possible without holding a whole file in memory.
The difference between the two formats is not syntactic, it is architectural. A JSON array is one document that happens to contain many records, so a reader has to see the closing bracket before it knows the document is complete. NDJSON — also sold as JSON Lines or .jsonl — makes each record its own document, and the newline becomes the framing. Everything that follows falls out of that one decision.
The same data in both shapes
[
{ "ts": "2026-11-24T09:00:01Z", "level": "info", "msg": "boot" },
{ "ts": "2026-11-24T09:00:04Z", "level": "warn", "msg": "slow query" }
] {"ts":"2026-11-24T09:00:01Z","level":"info","msg":"boot"}
{"ts":"2026-11-24T09:00:04Z","level":"warn","msg":"slow query"} Nothing was escaped, wrapped or renamed. The indentation and the outer brackets disappeared, and each line is independently parseable by the same JSON.parse you would use on the array.
Why a wrapping array blocks streaming
- ▸You cannot append. Adding a record to a pretty array means reading the file, removing the last bracket, writing a comma and the new element, then re-closing it. A writer that is interrupted halfway leaves a file that will never parse again. Appending one line is a single write and is atomic at the line boundary.
- ▸A reader needs the end. A parser working on an array either buffers the whole document or has to reconstruct partial state. With one value per line, a reader can process line 1 while line 400 is still being written.
- ▸Damage spreads. One malformed byte inside a large array loses the entire file. In NDJSON it loses one line, and the line number in the parse error tells you which record was broken.
- ▸Compression concatenates. gzip files are simply glued together and the result still decomposes to a valid stream, because each member is a byte stream that ends on a line boundary. That property is used by log rotation every day; it does not hold for a compressed JSON array.
What actually expects this format
- ▸Elasticsearch and OpenSearch bulk APIs take one action line followed by one document line per record.
- ▸BigQuery loads take
NEWLINE_DELIMITED_JSON, and so do most warehouse ingestion paths for the same reason: a 200 GB file cannot be one document. - ▸MongoDB's
mongoexportandmongoimportdefault to it; the.jsonlextension is theirs. - ▸
jqreads a stream of JSON values, so piping NDJSON through it works without any flag, while a pretty array needs.[]. - ▸Vector, Fluent Bit, Filebeat and most log shippers emit one event per line.
- ▸Spark, Hive and Hadoop
textformats split files on newlines across executors, which only works if a record never spans a line.
The rules that keep a file valid
- 01 Every line must be one complete JSON value on its own — object, array, string or number. A pretty-printed record spread over five lines is five invalid lines.
- 02 Literal newlines inside a string must be escaped as
\n. Serialisers do this for you; a hand-builtechoof a raw message will not. - 03 Use UTF-8 without a byte order mark. A BOM makes the first line of the file unparseable while the rest works, which is a memorable way to lose an hour.
- 04 Skip empty lines on read. Most writers end the file with a newline, and treating a blank line as a record produces a spurious null or an error.
- 05 Do not put commas at the end of lines. That is a JSON array habit, and in NDJSON the comma becomes part of the value.
What you give up
There is no place for top-level metadata. An array can carry { "generated": "…", "records": […] }; a line stream cannot describe itself, so pipelines either put a header record on line 1 and tell readers to expect it, or move the metadata to a sidecar file. There is also no single root value to hand to a schema validator, so validation runs per line — which is usually what you wanted anyway, because one bad record should not stop a reimport.
Converting without a script
Paste the array into the workbench and run JSON to NDJSON to get one record per line; the reverse lives on NDJSON to JSON, which collects lines back into an array so the schema, CSV and query modules can work on the whole set. If the source is a pretty-printed array of objects and you need lines, convert to NDJSON rather than minifying — minifying gives you one very long line, which is still a single document. To check what actually landed on each line, feed the result through schema inference: merged required fields are the keys every record agreed on.
A short checklist before you ship one
- ▸Does the consumer document say array or lines? Bulk APIs are unforgiving about the difference.
- ▸Is every record terminated by exactly one newline, including the last?
- ▸Are ids and timestamps strings, so nothing is reinterpreted by a numeric parser?
- ▸Can you rebuild the file from any prefix of itself? If yes, the format is doing its job.