JSONL vs JSON
JSON stores one value per file, usually a big array that has to be parsed all at once. JSONL (JSON Lines, also called NDJSON) stores one JSON value per line, so every record stands on its own. In short: use JSON for documents and API responses, and JSONL for large collections of records that you stream, append to, or process one at a time, such as logs, data exports, and LLM datasets.
The same data in JSON and JSONL
As a JSON array:
[
{ "id": 1, "event": "signup", "user": "ada" },
{ "id": 2, "event": "login", "user": "ada" },
{ "id": 3, "event": "purchase", "user": "linus", "amount": 59.9 }
]As JSON Lines:
{"id": 1, "event": "signup", "user": "ada"}
{"id": 2, "event": "login", "user": "ada"}
{"id": 3, "event": "purchase", "user": "linus", "amount": 59.9}There are no enclosing brackets and no commas between records: the newline is the separator. View or convert files with the JSONL viewer.
Side-by-side comparison
| Aspect | JSON | JSONL / NDJSON |
|---|---|---|
| Structure | One top-level value | One value per line |
| Parsing | Whole file at once | Line by line (streamable) |
| Appending a record | Rewrite the array | Write one more line |
| Memory for huge files | Needs the whole document | One record at a time |
| A corrupt record | Whole file fails to parse | Only that line fails |
| Pretty-printing | Allowed | Not allowed (one line per record) |
| Splitting into chunks | Needs a parser | Split on newlines |
| Extensions / MIME | .json, application/json | .jsonl, .ndjson, application/x-ndjson |
Why JSONL took over logs and AI datasets
- Streaming: a reader can process record 1 while record 1,000,000 is still being written or downloaded.
- Appending: loggers and pipelines just write a new line; there is no closing
]to keep track of. - Fault isolation: one malformed record costs you one line, not the whole file, and the error points at a line number.
- Parallelism: files split cleanly at line boundaries for distributed processing.
That is why fine-tuning and evaluation datasets, batch API jobs, structured logs, and exports from BigQuery, MongoDB, and Elasticsearch commonly use JSONL.
Reading JSONL in code
Python:
import json
with open("data.jsonl") as f:
records = [json.loads(line) for line in f if line.strip()]
# or with pandas
import pandas as pd
df = pd.read_json("data.jsonl", lines=True)JavaScript (Node.js), streaming line by line:
import { createReadStream } from "node:fs";
import { createInterface } from "node:readline";
const lines = createInterface({ input: createReadStream("data.jsonl") });
for await (const line of lines) {
if (line.trim()) console.log(JSON.parse(line));
}Writing JSONL is the reverse: JSON.stringify(record) (or json.dumps(record)) for each record, joined with newlines.
When to use each
Use JSON when
- The data is one document: an API response, a config file, a single object graph.
- The file is small enough to load at once and people may read or edit it.
Use JSONL when
- You have many independent records: events, logs, rows, training examples.
- Files are large, grow over time, or are processed as a stream or in parallel.
Related tools
- JSONL Viewer: view JSONL as a table, find bad lines, convert to and from JSON.
- JSON Validator: check a single JSON document.
- TOON vs JSON: another format built for LLM work.
- JSONL to CSV: turn JSON Lines straight into a spreadsheet.
Frequently asked questions
What is the difference between JSONL and JSON?
A JSON file contains one JSON value, often a large array, that must be read and parsed as a whole. A JSONL (JSON Lines) file contains many JSON values, one per line, each parsed on its own. That makes JSONL easy to stream, append to, and process line by line.
Is JSONL the same as NDJSON?
Practically, yes. JSON Lines (JSONL) and newline-delimited JSON (NDJSON) describe the same format: one valid JSON value per line, separated by newline characters. The file extensions .jsonl and .ndjson are interchangeable for most tools.
Is a JSONL file valid JSON?
No. A JSONL file with more than one line is not a valid JSON document, because JSON allows only one top-level value. Each individual line, however, is valid JSON. Convert between them with the JSONL viewer and converter.
Why do LLM tools use JSONL?
Training sets, evaluation sets, and batch API jobs can hold millions of examples. JSONL lets tools stream them one record at a time, split them into chunks by line, and report errors per example, without loading one giant array into memory. OpenAI fine-tuning and batch files, for example, are JSONL.
How do I read a JSONL file in Python?
Read it line by line and parse each one: records = [json.loads(line) for line in open("data.jsonl") if line.strip()]. With pandas, use pd.read_json("data.jsonl", lines=True).
Can JSONL contain pretty-printed JSON?
No. Each record must sit on a single line, so pretty-printed (multi-line) JSON breaks the format. Newlines inside string values must be escaped as \n.