What is NDJSON? Complete Guide to Newline Delimited JSON
Updated September 2026
Quick Answer: What is NDJSON?
NDJSON (Newline Delimited JSON) is a text format where each line contains a single JSON object, separated by newline characters. It's perfect for streaming large datasets and processing records one at a time.
Understanding NDJSON Format
NDJSON, also known as Newline Delimited JSON or JSON Lines, is a text format that stores one complete JSON value per line, most commonly an object for record-oriented data. This format is particularly useful for:
- Streaming large datasets
- Processing records incrementally
- Log file formats
- Data exchange between systems
- Machine learning data preparation
NDJSON vs JSON vs JSONL
| Format | Structure | Use Case |
|---|---|---|
| JSON | Single object in array | API responses, config files |
| NDJSON | Multiple objects, one per line | Streaming, large datasets |
| JSONL | Same as NDJSON | Same as NDJSON |
NDJSON Example
Here's a simple NDJSON example with user data:
{"name": "John Doe", "age": 30, "email": "john@example.com"}
{"name": "Jane Smith", "age": 25, "email": "jane@example.com"}
{"name": "Bob Johnson", "age": 35, "email": "bob@example.com"}
NDJSON Format Specification
The NDJSON format follows these rules:
- Each line must contain exactly one complete JSON value
- Each value must be valid JSON (properly formatted)
- Values are separated by newline characters (\n)
- No trailing commas or array wrapping
- Empty lines should be ignored
Working with NDJSON in Different Languages
Python
import json
# Reading NDJSON
with open('data.ndjson', 'r') as f:
for line in f:
if line.strip():
data = json.loads(line)
print(data)
# Writing NDJSON
data = [{"name": "John", "age": 30}, {"name": "Jane", "age": 25}]
with open('output.ndjson', 'w') as f:
for item in data:
f.write(json.dumps(item) + '\n')
JavaScript
// Reading NDJSON
const fs = require('fs');
const readline = require('readline');
const fileStream = fs.createReadStream('data.ndjson');
const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity
});
rl.on('line', (line) => {
if (line.trim()) {
const data = JSON.parse(line);
console.log(data);
}
});
// Writing NDJSON
const data = [{"name": "John", "age": 30}, {"name": "Jane", "age": 25}];
const ndjson = data.map(item => JSON.stringify(item)).join('\n');
fs.writeFileSync('output.ndjson', ndjson);
NDJSON vs JSONL: Are They the Same?
Yes, NDJSON and JSONL are essentially the same format. Both terms refer to newline-delimited JSON files. The difference is mainly in naming:
- NDJSON - "Newline Delimited JSON" (more descriptive)
- JSONL - "JSON Lines" (shorter, more common)
💡 Pro Tip
While NDJSON and JSONL are the same format, JSONL is more widely adopted in the developer community. If you're building tools or APIs, consider supporting both terms for better discoverability.
Common NDJSON Use Cases
Data Streaming
Perfect for streaming large datasets where you need to process records one at a time without loading everything into memory.
Log Files
Many logging systems use NDJSON format because it's easy to append new log entries and parse incrementally.
Machine Learning
ML frameworks often use NDJSON for training data because it allows for efficient batch processing and streaming.
API Responses
Some APIs return NDJSON for large result sets to enable streaming responses and reduce memory usage.
NDJSON Tools and Converters
Need to work with NDJSON files? Check out these helpful tools:
Our JSONL Tools (Also Work with NDJSON)
- JSON to NDJSON Converter - Convert JSON arrays to newline-delimited records
- NDJSON Validator - Validate your NDJSON files for errors
- NDJSON Viewer - View and explore NDJSON files online
- NDJSON to JSON Converter - Convert newline-delimited records back to a single JSON array
- JSONL Parser - Parse and analyze NDJSON data
NDJSON Best Practices
- Validate each line - Ensure every line contains valid JSON
- Handle empty lines - Skip or ignore empty lines when processing
- Use streaming - Process large files line by line to avoid memory issues
- Consistent encoding - Use UTF-8 encoding for international characters
- Error handling - Implement proper error handling for malformed lines
How NDJSON Works
NDJSON has no enclosing structure. Each line stands alone, so a parser can read one record, process it, and discard it before touching the next line. That is what makes NDJSON ideal for streaming:
- Stream as it grows — tail an NDJSON file (e.g.
tail -f app.ndjson) and process new records the moment they are appended. - Split on line boundaries — divide huge files across machines or workers without parsing anything first.
- Append without rewriting — add a record by writing one more line to the end of the file.
- Survive bad lines — skip a malformed line and keep processing the rest, unlike a single JSON document where one error breaks everything.
For the mechanics in another syntax, see the JSONL parser guide. To compare the trade-offs directly, read our JSONL vs JSON comparison.
How to Open an NDJSON File
Any text editor opens NDJSON, but record-by-record browsing needs a dedicated tool:
- Online viewer — drop the file into our NDJSON Viewer to inspect records by line and find malformed JSON.
- Text editor — VS Code, Sublime Text, or even Notepad work for small files; each line is human-readable JSON.
- Command line — preview with
head -5 data.ndjsonor validate every line withpython -c "import json,sys; [json.loads(l) for l in sys.stdin]" < data.ndjson. - As a spreadsheet — convert first with our JSONL to CSV converter and open the result in Excel or Google Sheets.
Frequently Asked Questions
What is the difference between JSON and NDJSON files?
A JSON file holds a single large document — usually one array or object — that must be loaded and parsed all at once, which becomes a memory and performance problem at scale. An NDJSON file holds one complete JSON value per line, so parsers process records line by line, making it ideal for streaming, logging, and very large datasets.
How does NDJSON work?
NDJSON works by removing the enclosing structure: each line is a standalone JSON value separated by a newline character. Readers process one line at a time, which enables tailing growing files, splitting work across machines on line boundaries, and appending new records without rewriting the file.
How do I open an NDJSON file?
Open an NDJSON file in any text editor for a quick look, or use our NDJSON Viewer to browse records by line. To work with the data in a spreadsheet, convert it first with the JSONL to CSV converter.
Is NDJSON the same as JSONL?
Yes, NDJSON and JSONL are the same format. NDJSON stands for "Newline Delimited JSON" while JSONL stands for "JSON Lines." Both refer to the same text format where each line contains one complete JSON value.
What's the MIME type for NDJSON?
The standard MIME type for NDJSON is application/x-ndjson or application/jsonl.