JSONL vs NDJSON — Are They the Same Format?
JSONL vs NDJSON — Are They the Same Format?
Short answer: yes, they are the same format under two names. A .jsonl file and an .ndjson file with identical bytes are indistinguishable to any parser — competing naming conventions, not competing specifications.
That makes the naming question trivial and the real question harder: what separates a valid newline-delimited file from one that breaks? These four traps are why a file someone calls "valid JSONL" fails to load.
The Short Answer
One format: each line holds one valid JSON value, lines are separated by a line terminator, and there is no enclosing array and no commas between records. What differs is only the file extension, the MIME type some servers send, and which specification a vendor wrote. Renaming data.jsonl to data.ndjson fixes a tool that rejects the extension — as long as the bytes were valid to begin with. For the fundamentals in shorter form, see the NDJSON format rules explained.
🧠 Why This Format Exists: Append-Only Streaming
The format earns its place through one property ordinary JSON arrays cannot offer: you can write one without knowing how long it will be.
A JSON array is a single document. To emit a valid one you open with [, close every element with a comma, then close with ] — and only at the very end is it valid. There is no valid prefix of a JSON array: if your process dies mid-write, you are left with something entirely unparseable.
JSONL has no such problem. Line one is already a complete, valid JSON value, so a reader can parse each record the moment its terminator arrives, and a crash costs you the final partial line rather than the whole file.
That is why the format appears wherever writes are incremental and unbounded: LLM streaming APIs, log shippers, which tail a log and append events as they happen, and bulk-import endpoints, which accept uploads rather than one giant POST body. Major model providers likewise accept .jsonl batch files where each line is one request carrying a custom id, method, path, and body.
📜 The Specification Rules
The jsonlines.org rules are short and precise:
- The encoding is UTF-8, and only UTF-8.
- A byte order mark (U+FEFF) must not be included.
- Each line is a valid JSON value, and a line terminator (
\r\nor\n) follows each JSON value.
The ndjson.org convention says much the same and adds stricter requirements: line endings must be LF, blank lines are not allowed, and a trailing newline is recommended. Note the gap: jsonlines.org tolerates CRLF, NDJSON does not — which is why one file can pass a library and fail another.
JSONL vs NDJSON: Side-by-Side
| JSONL | NDJSON | |
|---|---|---|
| Extension | .jsonl |
.ndjson |
| MIME type | application/jsonl, application/x-jsonlines |
application/x-ndjson |
| Written spec | jsonlines.org | ndjson.org |
| Line endings | \n or \r\n |
\n only |
| Blank lines | Not addressed | Not allowed |
| Trailing newline | Expected | Recommended |
JSONL vs a plain JSON array
| JSON array | JSONL | |
|---|---|---|
| Envelope | [ … ] around everything |
None |
| Separator | Commas between elements | Line terminators |
| Streamable | No | Yes |
Where it sits against CSV and SSE
JSONL vs CSV is a structural gap, not a preference: CSV is a flat table with types inferred from text on import, so a leading zero in an ID column silently becomes a number, while a JSONL record nests and keeps its types. The JSON to CSV converter handles the hop. JSONL vs SSE is a category error — SSE is a wire protocol, not a file format, so strip its data: prefix first.
⚠️ The Four Traps That Actually Bite
Trap 1: The byte order mark
A UTF-8 BOM is the byte sequence EF BB BF at the start of the file. Some Windows editors and export tools add it by default. Per rule 2, it must not be there.
In a strict reader the BOM is not valid JSON whitespace, so the first line only fails, with an error pointing at the first character rather than the cause:
Unexpected token '', ... is not valid JSONThe most common real-world cause of "my JSONL is broken" — check the actual bytes:
head -c 16 data.jsonl | xxd00000000: efbb bf 7b 22 69 64 22 3a 31 7d ........{"id":1}
^^^^^ BOMFix it at the boundary: in Python read with encoding="utf-8-sig"; in Node use a TextDecoder with ignoreBOM: true.
Trap 2: CRLF versus LF
Windows tooling writes \r\n. Depending on how naive the parser is, you get two different behaviours:
// Survives CRLF — trimming removes the stray carriage return.
JSON.parse(line.trim());
// Fails on CRLF — the trailing \r is now part of the input.
JSON.parse(line);Browsers' fetch, Python's open() in universal-newlines mode, and Java's BufferedReader normalise the terminator for you — which is why a file that fails in one place works in another. Write LF if you control the producer.
Trap 3: Blank lines between records
Some log pipelines emit a blank line as a visual separator. NDJSON forbids blank lines; jsonlines.org leaves them undefined, and parsers split on them.
Pick a policy and state it, because "it depends on the library" gives inconsistent record counts across environments. Skip them silently and you lose accurate file line numbers; preserve them as empty records and numbering still matches the physical file, which is what makes triage possible.
Trap 4: Newlines inside string values
A JSON string cannot contain a literal newline — it must escape it as the two characters \n. So a record with a multi-line message stays on one physical line:
{"level":"error","message":"connection failed\nretrying in 30s"}If a pretty-printer wrapped your records across lines, the file is no longer JSONL: line one is {"level":"error","message":"connection failed and fails on unexpected end of input, and line two is orphaned. This trap appears accidentally most often, from pretty-printing a file you did not realise was newline-delimited. Keep records compact.
🔄 Converting a JSON Array ⇄ JSONL
jq does this correctly and losslessly. Array to JSONL:
jq -c '.[]' data.json > data.jsonlThe -c (compact) flag is not optional in practice: without it jq emits pretty-printed multi-line objects — that is trap 4, a file that looks fine and fails to parse. Back to an array:
jq -s '.' data.jsonl > data.json-s slurps every input into one array.
The shell fallback — and why to avoid it
If jq is unavailable, this pattern sometimes circulates:
sed 's/^{//; s/^}$//; s/^},\{0,1\}$/\n&/; 1s/^\[\n//; $s/^\n\]$//' data.json > data.jsonlIt is fragile: it depends entirely on the exact whitespace of the file it was written against — different indentation, a closing bracket on its own line, or trailing whitespace all produce silently corrupt output, and it cannot handle a string value containing } at the start of a line. Check the result with a real parser, and remember that every syntax class jq tolerates — trailing commas, comments — is covered in Common JSON Errors and How to Fix Them for the single-document case:
jq -c . data.jsonl > /dev/null && echo "every line parses"In the browser, the NDJSON Viewer accepts .json, recognises it as an array, and exports the records as JSONL.
🔍 Inspecting a File You Don't Control
When a file arrives from a vendor export or a log dump, the LangStop NDJSON Viewer tells you what it is and where it breaks — in the browser, with nothing uploaded:
- Accepts
.ndjson,.jsonl,.txt,.json,.logfiles or pasted text, auto-detecting the format from up to 200 non-empty lines so a.jsonarray arrives recognised. - Treats every physical line as one record, including blank ones, so the record number shown is the line number in your file. A malformed line is marked invalid with a column and never aborts the file.
- Schema hints summarise sampled keys and value types — an inferred key/type summary, not JSON Schema and not validation.
One honest limit. Below 4 MiB the document is held in the tab and survives a reload. Above 4 MiB only a session-scoped file handle is kept: the text streams into the worker, the tab becomes export-only — Save shows an explanatory notice instead of writing back into the page — and it reopens empty after a reload.
For scale rather than correctness, viewing large NDJSON datasets goes deeper on streaming; for record-by-record triage, see reading JSONL logs and NDJSON records.
The JSON Formatter works on a single in-memory .json document — not a JSONL tool: no record model, no per-line errors, no streaming. For everything else JSON, start at the JSON tools hub.
❓ FAQ
Are JSONL and NDJSON the same format? Yes — same content rules, two naming conventions. If the bytes parse as one, they parse as the other.
Why is my first JSONL line invalid when the rest are fine?
Almost always a UTF-8 byte order mark, which is not valid JSON and corrupts line one only. Check with head -c 16 file.jsonl | xxd for efbb bf at offset 0.
Do I need a trailing newline at the end of the file? jsonlines.org requires a terminator after each JSON value, and NDJSON recommends one at EOF. Most parsers tolerate a missing final newline.
Can a JSON array be streamed? Not as a valid document: a consumer cannot parse anything until it sees the closing bracket, and a truncated array is unparseable. JSONL exists because each record is independently valid — see what JSON actually is.
Is renaming .jsonl to .ndjson always safe?
It fixes extension rejection and nothing more. If the bytes contain a BOM, CRLF endings, or pretty-printed records, they were already invalid and the new name fails identically.
🚀 Summary
Four things decide whether a newline-delimited file loads: a leading BOM, CRLF endings, blank lines, and newlines smuggled into string values. Fix those and most "JSONL is broken" reports resolve. Underneath them is why the format exists — append-only streaming, which a JSON array cannot offer.
Related LangStop Tools
- NDJSON Viewer — Open any NDJSON, JSONL, or mislabelled JSON file, see which lines fail and why, and export only what is valid.