{ } JSON Workbench100% Private • Zero Server Uploads

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

AspectJSONJSONL / NDJSON
StructureOne top-level valueOne value per line
ParsingWhole file at onceLine by line (streamable)
Appending a recordRewrite the arrayWrite one more line
Memory for huge filesNeeds the whole documentOne record at a time
A corrupt recordWhole file fails to parseOnly that line fails
Pretty-printingAllowedNot allowed (one line per record)
Splitting into chunksNeeds a parserSplit on newlines
Extensions / MIME.json, application/json.jsonl, .ndjson, application/x-ndjson

Why JSONL took over logs and AI datasets

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

Use JSONL when

Related tools

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.