Both formats use exactly the same JSON syntax. The only difference is how many values a file holds.
The difference in one example
JSON: one root value, usually an array.
[
{ "id": 1, "event": "login", "user": "asha" },
{ "id": 2, "event": "purchase", "user": "daniel", "amount": 5998 }
]
JSONL: one complete value per line, no enclosing array, no commas between records.
{"id": 1, "event": "login", "user": "asha"}
{"id": 2, "event": "purchase", "user": "daniel", "amount": 5998}
Comparison
| JSON | JSONL | |
|---|---|---|
| Root values per file | Exactly one | One per line |
| Read without loading everything | Hard (needs a streaming parser) | Easy: read line by line |
| Append a record | Rewrite the closing ] | Write one more line |
| Split / parallelize | Must parse first | Split on newlines (split -l) |
| A corrupt record breaks | The whole file | Only that line |
| Pretty-printing | Allowed | Not allowed (one line per record) |
| Human readability | Good | OK for small records |
| Typical extension | .json | .jsonl, .ndjson |
When to use JSON
- Config files (
package.json,tsconfig.json, settings files): one document, edited by people. - API request and response bodies: one value per HTTP message.
- Small datasets you want to read in an editor.
When to use JSONL
- Logs and event streams: every log line is a record you can
grep,tail -fand append to. - Large exports and imports: MongoDB's
mongoimportand BigQuery's newline-delimited JSON loads read one record per line. - LLM batch and fine-tuning files: OpenAI and Anthropic batch inputs and most fine-tuning datasets are JSONL, one request or example per line.
- Data pipelines: Spark, DuckDB and pandas (
lines=True) all read JSONL directly and can process it in chunks.
A rule of thumb: if the data is a document, use JSON. If it is a stream of records, use JSONL.
Converting with jq
# JSON array → JSONL
jq -c '.[]' employees.json > employees.jsonl
# JSONL → JSON array
jq -s '.' employees.jsonl > employees.json
-c prints each value compactly on one line. -s (slurp) collects all lines into one array.
Converting with Python
import json
# JSON → JSONL
with open("employees.json") as src, open("employees.jsonl", "w") as dst:
for row in json.load(src):
dst.write(json.dumps(row, ensure_ascii=False) + "\n")
# Stream a JSONL file without loading it all
with open("events.jsonl") as f:
for line in f:
if line.strip():
event = json.loads(line)
With pandas: pd.read_json("events.jsonl", lines=True) and df.to_json("out.jsonl", orient="records", lines=True).
Common JSONL mistakes
- Pretty-printing records. A record spread over several lines breaks every JSONL reader.
- Wrapping the file in
[ ]or adding commas between lines. That makes it neither valid JSON nor valid JSONL. - Windows line endings. Most readers accept
\r\n, but some strict tools do not. Write\n. - A blank last line. Usually fine, but skip empty lines when you parse.
Related comparisons
- JSON vs YAML for config files.
- JSON vs TOON for sending data to LLMs.
- JSON vs JSONB for storing JSON in PostgreSQL.