JSON and NDJSON
By Jun Nguyen2 min read278 words

JSON and NDJSON

Technology
Technology

NDJSON (Newline Delimited JSON, also called JSON Lines or LDJSON) is a format where each line is a valid, standalone JSON object, separated by newline characters (

\\n
). This makes it ideal for streaming, logging, or processing large datasets line-by-line, since you don’t need to parse the entire file at once .


πŸ“Š NDJSON vs. Regular JSON

FeatureNDJSONRegular JSON
StructureOne JSON object per line, no outer array or commasCan be a single object, array, or nested structure
Streamingβœ… Easily stream-processed line-by-line❌ Must parse entire file/array at once
Appending Dataβœ… Just add a new line β€” no need to modify structure❌ Must rewrite the entire array/object
Memory Efficiencyβœ… Low memory usage β€” process one line at a time❌ High memory usage β€” entire structure loaded
File SizeSlightly larger due to repeated keys and no compressionMore compact in arrays with shared structure
Tooling Supportβœ… Works with
grep
,
awk
,
jq -c
, etc.
❌ Harder to process with line-based tools
MIME Type
application/x-ndjson
application/json

✏️ Example Comparison

Regular JSON:

[ {"name": "Alice", "age": 30}, {"name": "Bob", "age": 25} ]

NDJSON:

{"name":"Alice","age":30} {"name":"Bob","age":25}

βœ… Use Cases for NDJSON

  • Log aggregation (e.g., ELK stack)
  • Bulk data ingestion (e.g., Elasticsearch
    _bulk
    API)
  • Real-time event streaming
  • ETL pipelines with large datasets

⚠️ Notes

  • NDJSON is not valid JSON as a whole, because it contains multiple top-level JSON texts .
  • Avoid pretty-printing β€” each line must be compact JSON to avoid breaking the format .

In short: Use NDJSON when you need to stream or append structured data efficiently. Use regular JSON when you need a single, complete data structure.