JSON Lines (JSONL): What It Is and 6 Mistakes to Avoid
If you work with logs, LLM fine-tuning data or data exports, you have met JSON Lines (JSONL). It is simple, but it has traps that regular JSON does not. What it is One valid JSON value per line, separated by
If you work with logs, LLM fine-tuning data or data exports, you have met JSON Lines (JSONL). It is simple, but it has traps that regular JSON does not.
What it is
One valid JSON value per line, separated by newlines:
{"id": 1, "name": "Ada"}
{"id": 2, "name": "Linus"}
No surrounding array, no commas between records.
Why use it
- Streaming: you can process one line at a time without loading the whole file.
- Append-friendly: add a record by appending a line.
- Fault tolerant: one bad line does not invalidate the rest.
Common mistakes
- Pretty-printing records. A record spread over several lines is no longer valid JSONL. Keep each object on a single line.
-
Wrapping in an array.
[and]make it ordinary JSON, and line-based tools stop working. - Trailing blank lines. Some parsers choke on an empty last line. Skip empty lines when reading.
-
Windows line endings.
\r\nleaves a stray\rat the end of each line in naive splits. Trim it. -
Newlines inside strings. They must be escaped as
\n. A raw newline splits the record. - Mixed schemas. Nothing enforces consistent keys, so validate each line against the shape you expect.
Convert between JSON and JSONL
In JavaScript, lines.map(JSON.parse) turns JSONL into an array, and arr.map(JSON.stringify).join("\n") goes the other way. For quick checks and conversions, use the browser tool below; your data never leaves the page.
Try it: JSONL Formatter
Related: JSON Validator, JSON to CSV and JSON Formatter. All 590+ tools at webdevtoolbox.com run client-side.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.