Data & APIs

JSON vs NDJSON: When to Use JSON Lines

Compare JSON arrays and newline-delimited JSON for logs, streaming APIs, exports, and incremental processing.

Photorealistic editorial photo for Json Vs Ndjson
Data & APIs · Practical ideas for your next build

NDJSON stores one complete JSON value on each line. A conventional JSON export often stores all records inside one array. Both use JSON syntax for individual values, but they differ in how records are framed and processed. That difference matters when an export grows beyond what you want to load into memory.

Choose arrays for complete documents

A JSON array is convenient for small API responses and configuration that should be validated as one document. Standard JSON parsers accept it directly. The opening bracket, separators, and closing bracket are part of the document, so appending records to a file requires maintaining valid array syntax. A partially written array may not parse as a complete JSON document.

Choose lines for record streams

With NDJSON, a reader can process a completed line without waiting for the end of the file. This works well for log pipelines and batch exports. Each line must contain a complete JSON value; formatting one record across several physical lines breaks that framing. Newlines inside string values must be escaped using JSON syntax rather than inserted literally.

Understand conversion costs

Converting an array to NDJSON removes only the outer array and serializes each member independently. Converting back collects values into a new array. Our browser converter loads the full input in memory, so it is a convenient conversion tool rather than a streaming engine for multi-gigabyte files. Use a streaming parser or command-line pipeline when file size exceeds a comfortable browser workload.

Worked example

EXAMPLE
JSON: [{"id":1},{"id":2}]
NDJSON:
{"id":1}
{"id":2}

Are NDJSON and JSON Lines equivalent?

They share the one-JSON-value-per-line approach. Check the receiving system for conventions about blank lines, final newlines, and accepted value types.

Reference and further reading

Read the official documentation ↗