Introduction
JSON Lines is a text file of JSON values, one per line. Because each line stands alone, a program can read a huge file one record at a time, append new records to the end, or split the file between workers, none of which is easy with a single large JSON array.
It is used for logs, data exports and machine learning datasets, such as the training
and evaluation files of many language model tools. The same idea is also published as
NDJSON (newline-delimited JSON), with the extension .ndjson.
Structure
The file is UTF-8 text. Each line holds one complete JSON value, usually an object,
written without line breaks inside it, and ends with a line feed (\n); a
carriage return before it is allowed. The last line should also end with a line feed.
Blank lines are not part of the format, although many readers skip them.
Nothing requires every line to have the same fields, but most files hold one kind of record, like the rows of a table.
Links
Software
- Visual Studio Code (Windows, macOS, Linux)
- jq, which reads one value after another (Windows, macOS, Linux)
- DuckDB, which queries JSON Lines files with SQL (Windows, macOS, Linux)
Developers
Reference
- JSON Lines, the description of the format
- NDJSON specification