Skip to main content

Why Choose NDJSON?

40 compelling advantages that make NDJSON the format of choice for streaming data, big data processing, and modern applications

A sleek streamlined train of NDJSON records racing ahead of a heavy cargo block of a single JSON array

Streaming & Performance

1. True Streaming (Read)

This is the main advantage. You can read and parse the file one line at a time.

Comparison:

A standard JSON file (as an array) must be read entirely into memory before you can parse it. This is impossible for a 50GB file on a machine with 16GB of RAM.

2. True Streaming (Write)

You can easily append new records. To add a new log, you just append a new line to the file.

Comparison:

To add an item to a standard JSON array, you must read the entire file, parse it, add the new item to the in-memory array, and then serialize and write the entire file back to disk.

3. Extremely Low Memory Footprint

Since you only process one line at a time, the memory required is minimal, regardless of whether the file is 10MB or 10TB.

Use Case:

A web server writing log entries. It just appends strings to a file, which is incredibly fast and light on resources.

4. Instant First-Record Processing

Your program can begin processing the very first record as soon as it's read, without waiting for the entire file to download or be parsed.

Use Case:

A real-time dashboard reading from a live data feed. It can update statistics instantly as each new line (event) arrives.

5. Robust Error Handling

A syntax error or data corruption on one line only affects that single record.

Comparison:

In a standard JSON array, one missing comma or extra bracket can make the entire file unparseable. In NDJSON, you can simply skip the malformed line and continue.

Big Data & Parallelism

6. Trivially Parallelizable

You can easily split a 1-billion-line NDJSON file for parallel processing.

Example:

Give lines 1-1,000,000 to Core 1, lines 1,000,001-2,000,000 to Core 2, etc. Each line is an independent JSON object, so no coordination is needed.

Comparison:

This is extremely difficult with standard JSON, as you can't just "split" the file in the middle of an object.

7. MapReduce & Big Data Friendly

NDJSON is a native format for many big data systems (like Apache Spark, Hadoop, and AWS Step Functions).

Reasoning:

The "Map" step in a MapReduce job can operate on each line independently, making it a perfect fit for this processing model.

8. Splittable for Transfer

You can easily split a large NDJSON file into smaller chunks for network transfer and reassemble them by simple concatenation.

Comparison:

You cannot "split" a JSON file without breaking its syntax. You would have to parse it, split the array, and re-serialize each chunk into a new, valid JSON file.

9. Simple Record Counting

Counting the number of records is as simple as counting the number of lines.

Example (PowerShell):

(Get-Content my_data.jsonl).Count

Comparison:

To count records in a standard JSON array, you must parse the entire file and get the length of the array.

Data Structure & Format

10. Full JSON Type Support

Each line is a full JSON object, so you retain all the benefits of JSON over simpler formats.

Comparison (vs. CSV):

CSV is flat. It cannot natively represent nested objects ({"user": {"id": 123}}) or arrays ({"tags": ["a", "b"]}). NDJSON handles these perfectly.

11. No "Escaping" Hell

Formats like CSV break if your text contains a comma or a newline. This requires complex escaping rules ("Hello, world").

Reasoning:

In NDJSON, a newline or comma inside a string value is just part of the JSON string ({"comment": "Hello,\nworld"}). It doesn't break the format's structure.

12. Schema Flexibility

You can have different object structures on different lines. Line 1 could be {"event": "login", "user": 1} and Line 2 could be {"event": "error", "code": 500, "details": "..."}.

Use Case:

Perfect for logging, where different event types have different data payloads.

Comparison (vs. CSV):

A CSV file has a rigid column structure that all rows must follow.

13. Less Verbose than XML

NDJSON is far more concise than its equivalent in XML.

Comparison (vs. XML):

NDJSON: {"id": 1, "name": "Alice"}

XML: <record><id>1</id><name>Alice</name></record>

The XML version is much larger and harder to read.

Tooling & Usability

14. Works with Standard Unix/PowerShell Tools

You can use common text-processing tools directly on NDJSON files.

  • grep / Select-String: Find lines (records) containing specific text
  • head / Get-Content -TotalCount: Get the first N records
  • tail / Get-Content -Tail: Get the last N records or follow a log file in real-time
  • wc -l: Count the total number of records

15. Simple to Generate

It's incredibly easy to write a program that generates NDJSON. You just loop, serialize your object to a JSON string, and print it with a newline.

16. Simple to Parse (Manually)

You don't need a special "NDJSON library." You just need a line reader and a standard JSON parser, which are built into every modern language.

17. Human-Readable (for large files)

It's easier for a human to open a 5GB NDJSON file and inspect the first few lines than it is to open a 5GB standard JSON file, which will likely crash any text editor.

18. Concatenation is Just "Cat"

You can merge two NDJSON files into one valid NDJSON file by simply concatenating them.

Example (PowerShell):

Get-Content file1.jsonl, file2.jsonl | Set-Content combined.jsonl

Comparison:

You cannot do this with standard JSON files.

19. Standard for Machine Learning Data

Many ML/AI platforms (like OpenAI and Google Vertex AI) use the NDJSON format for uploading training and batch-prediction datasets.

Reasoning:

Each line represents one training example or one prediction request, which maps perfectly to their streaming data pipelines.

20. No-Schema-Needed Data Dumps

It's an excellent format for "dumping" data from a database (especially NoSQL databases like MongoDB) for backup or transfer, as each document maps directly to one line.

Developer Experience & Debugging

21. Grep-Friendly Debugging

This is a major DX win. If you're looking for an object with "id": "xyz-123", you can grep for that string, and the entire line returned is the entire object.

Comparison:

In a standard, pretty-printed JSON file, grep would only return the single line with the ID, giving you no context about the rest of the object.

22. Reduces Code Complexity

The parsing logic is often simpler. Instead of data = json.load(file_handle) (which reads all) followed by a loop, your code is just for line in file_handle: process(json.loads(line)). This is more linear and intuitive.

23. Trivial Data Sampling

Need a random sample of 1,000 records from a 1-billion-record file?

Example (PowerShell):

Get-Content data.jsonl | Get-Random -Count 1000

Comparison:

With a standard JSON array, you'd have to parse the entire file, load all 1 billion records into an array, and then sample it.

24. Easy Data Patching

If you find one bad record (e.g., on line 50,342), you can use a tool like sed or a simple script to find and replace just that line.

Comparison:

To patch one record in a standard JSON array, you must parse the whole file, find the item, change it, and re-serialize the entire file.

25. "Dumb" Tool Compatibility

Because it's line-based, it works with tools that know nothing about JSON.

Use Case:

The Linux split command can break a 10GB NDJSON file into 10 1GB files (split -l 1000000 data.jsonl), and each one is still a valid NDJSON file. This is impossible with a JSON array.

Ecosystem & Interoperability

26. Database-Native Format

Many modern databases use this format for bulk import/export. MongoDB's mongoexport produces NDJSON by default. Google BigQuery and Azure Data Lake have first-class support for it. (AWS S3 Select did as well, but Amazon closed it to new customers in July 2024.) The platform case studies show how Elasticsearch, ClickHouse, and DuckDB handle it in production, with each claim traced back to vendor documentation.

27. First-Class Logging Format

It is the de facto standard for structured logging. Tools like Filebeat, Logstash (part of the ELK stack), Splunk, and Fluentd are built to read logs line-by-line and are optimized to parse NDJSON.

28. Natural for Message Queues

A stream of messages in Kafka, RabbitMQ, or AWS SQS is conceptually identical to an NDJSON file. Each message is a self-contained JSON object, and the "topic" is the (never-ending) file.

29. Implicit Language Support

You never need to find a "NDJSON library" for your language. You only need two things every language has: 1) a line reader, and 2) a JSON parser. This gives it universal, out-of-the-box compatibility.

30. Superior to "Concatenated JSON"

A common anti-pattern is just mashing JSON objects together ({"id":1}{"id":2}). That is not valid NDJSON: the spec requires exactly one JSON value per line, so a standard parser stops at the second object. NDJSON formalizes the newline-separated version of this intuitive (but previously non-standard) idea, and the newline is what makes it parseable. The history of the format explains how an ad hoc convention ended up documented as a spec.

Specific Data Patterns & Use Cases

31. Ideal for Change Data Capture (CDC)

An NDJSON file is a perfect way to represent a stream of database changes.

Example:

{"op": "INSERT", "data": {"id": 1, "name": "Alice"}}
{"op": "UPDATE", "id": 1, "change": {"name": "Alicia"}}
{"op": "DELETE", "id": 1}

32. Handles "New Column" Evolution

Solves a classic CSV problem. If you add a new field to your data, you just add the new key-value pair to new lines.

Example:

{"id": 1, "name": "A"}
{"id": 2, "name": "B", "new_field": "x"}

Parsers not aware of new_field will simply ignore it, making the format forward-compatible. In CSV, this would break all column indexing.

33. Niche Caching Strategy

For a large, read-only set of key-value data, you can use an NDJSON file as a "grep-able" cache. Instead of loading a 2GB JSON into memory, you can grep the file for the key (e.g., "id": "user-456") to retrieve the record, which is slow but uses zero RAM.

34. Partial File Merging

If you have 10 servers all writing their own logs.jsonl, you can merge them into one master file by simple file concatenation. Merge closed or rotated files: a file still being written can end in a half-written line with no newline, which corrupts the record that follows it in the merged output.

35. Avoids XML's Complexity

It provides a structured record format without the baggage of XML.

Comparison (vs. XML):

NDJSON has no schemas (XSD), no namespaces (xmlns), no DTDs, and no complex attribute-vs-element debates. It's just data.

Performance & Stream Mechanics

36. Lower Time-to-First-Byte (TTFB)

When streaming from an API, the server doesn't have to gather all 1,000 results into an array. It can serialize and send the first object immediately, lowering perceived latency for the client.

37. No "Look-Ahead" Parsing

A standard JSON array parser must "look ahead" to find the closing ] to know it's done. An NDJSON parser has a simpler job: read until you hit \n, parse, repeat. This is a simpler and faster state machine.

38. Safe File Rotation

Operations teams can safely rotate NDJSON log files. They can mv app.jsonl app.jsonl.1 and tell the app to re-open its file handle. The file is never "corrupted" by being incomplete.

Comparison:

Doing this to a standard JSON array file would leave a permanently broken, unclosed array in app.jsonl.1.

39. Simple Stream Termination

A program generating an NDJSON stream doesn't need to know when the "end" is to add a special closing character. It just stops writing. The stream is valid whether it has 1 line or 1 billion.

40. Compresses Well (in Streams)

Because the structure (the JSON keys) is repeated on every line, NDJSON compresses very effectively with gzip. More importantly, you can pipe it through a compression stream (e.g., cat data.jsonl | gzip > data.jsonl.gz) without loading it all into memory.

Pipelines iconWhich Advantage Matters for Your Workload

Forty advantages is a long list. For any one job, two or three of them do the real work. Find your workload below.

Chart matching six workloads to the advantage that matters most: logs to append-only writes, fine-tuning data to one example per line, large API exports to streaming, parallel batch jobs to splitting at any newline, big files on a small machine to constant memory, and data in version control to line-based diffs
For any one job, two or three advantages do the real work.
WorkloadThe advantage that paysWhat it means in practice
Application and container logsAppend-only writesA crash can damage the last line at most. Every earlier record is still readable
LLM fine-tuning dataOne example per lineThe platform can count, shuffle and validate examples, and report a bad one by line number
Exporting a large result set from an APIStreamingThe client handles the first record before the server has produced the last
Batch ETL across many workersSplittable at any newlineCut the file into ranges and process them in parallel with no coordination
Debugging a production incidentPlain textgrep, head, tail -f and jq work on it directly, with nothing to install
Big files on a small machineConstant memoryA reader holds one line at a time, so file size stops mattering
Datasets kept in version controlLine-based diffsA changed record shows up as one changed line in a diff or a code review
Messages on a queue or socketSelf-delimiting recordsThe newline is the frame, so no length prefix or envelope format is needed

Fault tolerant iconWhere NDJSON Is the Wrong Choice

A format that is good at everything does not exist. These are the jobs where something else is plainly better, and what to use instead.

Chart of five needs where another format is better: analytics on a few columns needs a columnar format, looking up one record by key needs a database, hand-edited settings need YAML or TOML, a guaranteed schema needs Avro or Protobuf, and large binary payloads need separate files
Five jobs where something else is plainly better.
If you needNDJSON struggles becauseUse instead
Fast analytics over a few columns of a wide tableEvery query has to read and parse every field of every recordA columnar format. See NDJSON vs Parquet
To look up one record by keyThere is no index. Finding a record means scanning the fileA database or key-value store, or build an offset index next to the file
To update or delete records in placeChanging a line means rewriting the file from that point onA database, or append a correction record and compact later
The smallest possible fileEvery key is repeated on every lineCompress it (gzip or zstd handle the repetition well) or move to a binary format
A small, hand-edited configuration fileOne record per line is awkward to read for nested settingsPretty-printed JSON, YAML or TOML
A guaranteed schemaNothing in the format enforces field names or typesValidate each line with a JSON Schema, or use Avro or Protobuf
Large binary payloadsBinary has to be base64-encoded, which adds about a third to its sizeStore the files separately and put their paths in the records

Specification iconHonest Answers About the Advantages

Is NDJSON faster than JSON?

Parsing a byte of JSON costs the same either way. NDJSON wins on time to first record and on memory: work starts after the first line and never needs the whole file loaded. For a file that fits comfortably in memory the difference is small.

Is an NDJSON file smaller than a JSON file?

About the same. It is smaller than pretty-printed JSON because there is no indentation, and nearly identical to compact JSON: it trades commas and two brackets for newlines.

Is NDJSON better than CSV?

For nested data, mixed types and text that contains commas or line breaks, yes. For a flat table that people will open in a spreadsheet, CSV is smaller and friendlier.

Does NDJSON work with compression?

Very well. Repeated keys compress away almost completely, and gzip and zstd both decompress as a stream, so you can still read the first records without unpacking the file.

Can several programs write to one NDJSON file?

Only with care. Short appends to a file opened in append mode usually stay whole on a local disk, but that is not a guarantee everywhere. Give each writer its own file, or put a single writer in front of the file.

Do I lose anything by choosing NDJSON first?

Rarely. Converting NDJSON to Parquet, CSV or database rows later is a one-line job, which makes it a safe landing format when you do not yet know how the data will be used.

Ready to Learn More?

Explore detailed comparisons, understand the disadvantages, and discover when NDJSON is the right choice for your project.