NDJSON (JSON Lines)
NDJSON — newline-delimited JSON — is a text format with one complete
JSON value on each line. No enclosing array, no commas between
records. The same convention ships as JSON Lines, with the extension
.jsonl.
{"id":1,"status":"passed","ms":412}
{"id":2,"status":"failed","ms":1290}
{"id":3,"status":"passed","ms":388}
The equivalent JSON is one array that must be read to the final ]
before any of it is valid.
Why it exists
| Need | JSON array | NDJSON |
|---|---|---|
| Process a 10 GB file | Load it all, or a streaming parser | Read a line, parse a line |
| Append a record | Rewrite the closing ] |
Write one line |
| Survive a truncated write | Whole file invalid | Lose the last line |
| Split across workers | Hard | split -l |
grep / wc -l / tail -f |
Meaningless | One record per match |
That is why it is the default shape for structured logs, Elasticsearch's
_bulk API, BigQuery and Snowflake loads, OpenAI-style batch and
fine-tuning files, and most streaming HTTP responses.
The rules
- One JSON value per line. Usually an object, but any value is legal.
- No raw newlines inside a value — they must be escaped as
\n, which every JSON serialiser already does when not pretty-printing. - UTF-8. A byte order mark at the start breaks the first line in strict parsers.
- Blank lines are commonly skipped, but not every reader tolerates them.
Converting
- NDJSON → JSON array:
jq -s . file.ndjson, or in JavaScripttext.split("\n").filter(Boolean).map(JSON.parse). - JSON array → NDJSON:
jq -c '.[]' file.json. - CSV → NDJSON: the CSV to JSON converter has an NDJSON output shape.
- NDJSON → table: JSON to HTML table and JSON to CSV both accept NDJSON input when the text isn't a single JSON document.
Making it readable
NDJSON is built for programs. When a person needs to look at the records — a failed batch, a slice of logs — a rendered table they can sort and comment on beats a 4,000-column-wide line in a terminal. Paste the lines into JSON to HTML table and share the result as a link.
Try it
Comma is free — unlimited reports, unlimited commenters, unlimited revision history.
Turn NDJSON into a shareable table →