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 text in which each line holds one complete JSON value. Most files hold
objects, but a value of any kind is allowed, including null. Nothing requires
every line to have the same fields, though most files hold one kind of record, like the
rows of a table.
{"id": 1, "name": "Ada"}
{"id": 2, "name": "Grace", "langs": ["en"]}
{"id": 3, "name": "Linus"}
Two descriptions of the format exist, JSON Lines and NDJSON. They agree on the structure and differ in a few details:
| Rule | JSON Lines | NDJSON 1.0.0 |
|---|---|---|
| Encoding | UTF-8 | UTF-8 |
| Byte order mark | Must not be included | Not mentioned |
| What each line holds | A valid JSON value | A JSON text conforming to RFC 8259 |
| Line breaks inside a value | Not possible: a value is one line | Must not contain line feeds or carriage returns |
| Line terminator | \n; \r\n works because white space around a value is ignored | \n (0x0A), which a \r (0x0D) may precede |
| Terminator after the last value | Strongly recommended, not required; if present it must be the last byte | Required: each text is followed by a line feed |
| Blank lines | Not valid | A parser may skip them silently, if that is documented, and should let the user configure it |
| A line that does not parse | Not stated | The parser should raise an error |
| File extension | .jsonl | .ndjson |
| Media type | application/jsonl, “not yet standardized” | application/x-ndjson |
Lines and line ends
Only the line feed ends a line. A carriage return before it is harmless, because white space around a JSON value is ignored, but a carriage return alone, as in old Mac text, does not end a line. So the sequence below is one line, and not a valid record:
{"a":1}␍{"b":2}
A value must stay on one line. Line feeds inside a string are written as the
\n escape, so they
never appear as raw line breaks, and a line can always be taken to be a whole record. A
pretty-printed value spread across several lines is not a valid record, even though each
piece would be fine as ordinary JSON.
Each record is independent, so one bad line does not make the others unreadable: a program can report it and carry on with the next line.
Encoding
Both descriptions require UTF-8, with the byte order mark excluded by JSON Lines. JSON’s other rules apply to each value in the usual way, including its strings and numbers. Characters above ASCII can be written as themselves or escaped: the format does not ask for ASCII.
Media types and file extensions
Neither media type is in the IANA register, as of November 2026. jsonlines.org gives
application/jsonl and says it is not yet standardised, while the NDJSON
specification asks for application/x-ndjson, and software uses either.
The extension is .jsonl for JSON Lines and .ndjson for NDJSON.
Some tools write the same data with a plain .json extension, which says nothing
about the line structure.
Compression
jsonlines.org recommends stream compressors such as gzip and bzip2, giving files named
.jsonl.gz or .jsonl.bz2. Text with one kind of record per line
compresses well, and because each compressor works as a stream, a reader can decompress
and handle the file a record at a time without holding it all in memory. Inside the
compressed data, the format is exactly the same.
JSON text sequences
Another way of storing several JSON values in one file is
RFC 7464, JSON text sequences, with the
media type application/json-seq. Each value starts with a record separator byte,
0x1E, and ends with a line feed, so a value can itself contain line breaks.
Unlike JSON Lines, it is a registered standard, but it is much less common.
Links
Software
- Visual Studio Code – free code editor, for reading and editing the lines as text (Windows, macOS, Linux)
- jq – command-line JSON tool that reads one value after another (Windows, macOS, Linux)
- DuckDB – analytical database that queries JSON Lines files with SQL (Windows, macOS, Linux)
Developers
Reference
- JSON Lines – the description of the format
- NDJSON specification – the same idea published as newline-delimited JSON
- RFC 7464 – JSON text sequences, a related format with a record separator byte