JSON vs. JSONL and NDJSON

Learn why line-delimited JSON is useful for records, how to validate each line, and when to convert to an array.

A JSON document contains one root value. A JSONL or NDJSON file contains a sequence of independent JSON values, one per line. Two adjacent objects without an array are not one valid JSON document, even though each line may be valid on its own.

Two records in two formats

JSON array:

[
  { "id": 1, "name": "Alex" },
  { "id": 2, "name": "Sam" }
]

JSON Lines:

{"id":1,"name":"Alex"}
{"id":2,"name":"Sam"}

Line-delimited data is convenient for logs and streaming because a consumer can process one record at a time. The array is convenient when a program expects a single JSON value. A newline inside a JSON string must be escaped as \n; an actual line break would split the record.

Validate and convert

Open the JSONL and NDJSON validator to check each line and see an error with its line number. It converts JSONL to a JSON array, or an array back to lines. A blank interior line is treated as an error, so a missing record does not pass unnoticed.

If your data is a CSV spreadsheet export, use CSV to JSON instead. CSV quotes and commas obey a different grammar, and a CSV record may legitimately span multiple physical lines. For one ordinary JSON file, use the JSON validator.

Already have valid JSON? Make it readable