What Is a JSON Lines File (JSONL)?

JSON Lines (also called JSONL or NDJSON) stores one valid JSON value per line with no surrounding array or wrapping object. The file itself is not valid JSON — that's intentional.

What it looks like

{"id":1,"name":"Alice","role":"admin"}
{"id":2,"name":"Bob","role":"editor"}
{"id":3,"name":"Carol","role":"viewer"}

Each line is a self-contained JSON document. Lines are separated by \n, and a trailing newline is fine.

Why not a JSON array?

A regular JSON array requires the parser to load the entire file before it can process anything. JSONL changes that:

  • Stream it — read one record, process it, discard it, repeat. Memory stays constant regardless of file size.
  • Append to it — write one new line to the end. No need to parse or rewrite the whole file.
  • Recover from errors — one malformed line doesn't invalidate the rest. Each line fails or succeeds independently.

This is why log aggregators (Fluentd, Logstash), ML training datasets (Hugging Face), and ETL pipelines default to JSONL.

Reading JSONL in code

Split on newlines, parse each line:

const lines = fs.readFileSync("data.jsonl", "utf8").trim().split("\n");
const records = lines.map(line => JSON.parse(line));

Or stream it with readline to keep memory low on large files:

import readline from "readline";
import fs from "fs";

const rl = readline.createInterface({ input: fs.createReadStream("data.jsonl") });
rl.on("line", line => process(JSON.parse(line)));

In Python:

with open("data.jsonl") as f:
    records = [json.loads(line) for line in f]

JSONL vs NDJSON

They're the same format — different acronyms. NDJSON stands for "newline-delimited JSON." The .jsonl extension is more common for files; application/x-ndjson is the registered MIME type.

Validate your JSONL

If a JSONL pipeline misbehaves, isolate the bad record: paste one line at a time into the JSON validator. Each line must be independently valid JSON. Fix the line, and the pipeline picks right back up.

For a review of what makes JSON itself valid, see common JSON syntax errors.

Got a config file to check?

Open the config toolkit →