JSON versus JSONL and NDJSON

JSON vs JSONL and NDJSON: how the formats differ, what converting between them changes, and how to choose one for APIs, config files, logs or bulk data.

JSON, JSON Lines (JSONL) and newline-delimited JSON (NDJSON) all use the same syntax for individual values. They differ in how values are framed in a file or stream. A JSON document is a single value. JSONL and NDJSON are sequences of separate JSON values, one per line. That framing decides which tools can read the data, how it can be appended to or streamed, and whether a validator will accept it.

What the conversion actually changes

Converting between JSON and JSONL is a structural change, not a change to the data. The keys, values, types and nesting inside each record stay the same. Only the container and the whitespace change: the wrapping array, the commas between records and any pretty-printing indentation.

  • A JSON document holds exactly one top-level value, often an object or an array. Whitespace between tokens is insignificant, so the same document can be minified onto one line or pretty-printed across many.
  • A JSONL or NDJSON file holds many top-level values. Each one sits on its own line, and the newline character separates records. There is no enclosing array and there are no commas between records.
  • Because the newline is the separator, a record cannot be pretty-printed across several lines. Line breaks inside string values must stay escaped as \n, which JSON already requires.
  • A multi-line JSONL file is not a valid JSON document. A strict JSON parser or validator will normally reject it after the first value. A file with exactly one line is the exception, because that line is itself a valid JSON text.

The following matched example shows the same three records in each form. It was written to illustrate the structure and is not output from any particular tool.

JSON (one array value, pretty-printed):
[
  {"id": 1, "event": "login", "user": "ana"},
  {"id": 2, "event": "upload", "user": "ben"},
  {"id": 3, "event": "logout", "user": "ana"}
]

JSONL / NDJSON (three values, one per line):
{"id": 1, "event": "login", "user": "ana"}
{"id": 2, "event": "upload", "user": "ben"}
{"id": 3, "event": "logout", "user": "ana"}

In this case the conversion is reversible. You can wrap the lines in brackets and add commas to get the array back, and the data comes through unchanged. Two things are not preserved. Original indentation and spacing are lost. And if the JSON top level is a single object rather than an array, nothing defines how it should split into lines, so you have to decide which nested array, if any, becomes the records.

JSONL versus NDJSON: is there a difference?

In practice the two names describe the same format: UTF-8 text with one valid JSON value per line, separated by a line feed. They were published as separate community specifications, which is why both names and both file extensions (.jsonl and .ndjson) are in use. The wording of the two specifications differs in details such as tolerating a carriage return before the line feed. Neither is a formal standards-body specification in the way JSON itself is.

Where tools can disagree is in edge-case handling rather than the core format. Check how your destination treats these cases:

  • Blank lines between records
  • A missing or extra trailing newline at the end of the file
  • Windows-style CRLF line endings
  • A byte order mark at the start of the file
  • Top-level values other than objects, such as bare strings or arrays

If a consumer documents one name, use that name's extension and media type. Expect files to work interchangeably once those edge cases match.

Which format suits your intended result

Criterion | JSON | JSONL / NDJSON
Top-level structure | One value | Many values, one per line
Valid as a single JSON document | Yes | Only if the file has one line
Appending a record | Usually requires rewriting the closing bracket | Write one more line
Reading record by record | Needs a streaming parser to avoid loading the whole value | Read and parse one line at a time
Effect of a truncated or corrupt file | The whole document fails to parse | Complete earlier lines remain readable
Pretty-printing | Allowed | Not allowed within a record
Human inspection | Easy when indented | Long lines; easiest to inspect one record at a time
Splitting or combining files | Requires restructuring the array | Line-based split and concatenation work if every file ends with a newline
Fits configuration and single API responses | Well suited | Poor fit

Choose plain JSON when the data is one logical unit: a configuration file, a single API response or request body, a settings export, or anything a person will read and edit by hand. The single-document guarantee and pretty-printing make it easier to validate and review.

Choose JSONL or NDJSON when the data is a collection of independent records that grows over time or is too large to handle in one piece. Typical cases are logs, event streams, bulk imports and exports, and datasets processed one row at a time. The line-based framing supports appending, streaming, parallel splitting and recovery from a damaged final line. The cost is that each record must stay on a single line, and ordinary JSON tools will not accept the file as a whole.

If a tool or service expects one format, its documentation settles the choice. Sending JSONL to an endpoint that expects a JSON array, or the reverse, usually produces a parse error rather than partial success.

Will the converted text remain usable where you need it?

Because JSONL depends on line breaks, anything that changes line endings or adds line breaks can break the data. The JSON content itself is unaffected.

  • Copy and paste: Some editors, chat tools and web forms convert line endings, strip trailing newlines or merge lines. After pasting JSONL, confirm that the line count matches the record count.
  • Soft wrapping: An editor that visually wraps long lines does not change the stored file. Hard wrapping or reformatting does change it and will split records.
  • Pretty-print commands: Running a general JSON formatter over a JSONL file will typically fail, or it may reformat only the first record. Format one record at a time, then re-compact it before saving.
  • Validation: A standard JSON validator checks one document. To validate JSONL, check each line separately and report the line numbers that fail.
  • Encoding: Both JSONL specifications call for UTF-8, and the JSON standard requires UTF-8 for data exchanged between systems. Converting through a tool that re-encodes text can corrupt non-ASCII characters.

For people reading the data, long single-line records are harder to scan visually and to follow when read aloud. This guide's sources did not include any assistive-technology testing for either format. If people need to read the data, provide a pretty-printed JSON view of individual records alongside the JSONL file. Keep the JSONL as the machine-facing format.

Many converters and formatters run in a web browser or on a remote server, and their documentation does not always say which. Do not paste credentials, tokens, personal data or production records into an online tool unless you know where the processing happens and what is retained. A local command-line tool or a short script in your own environment avoids sending the data anywhere.

Evidence gaps

This guide rests on the general structure of the formats. It does not cover:
• Tests of specific converters, validators or editors.
• Performance measurements.
• Comparisons of how particular platforms handle edge cases.
Treat the examples above as illustrative. Before relying on a workflow, test it against the exact destination that will consume your data.