Convert JSON to JSONL
What a JSON to JSONL converter changes, what it keeps, where line-delimited output breaks, and when a standard JSON document is the better choice.
Converting JSON to JSONL (JSON Lines) turns one JSON document, usually a top-level array, into a text file where each line holds one complete JSON value. This review covers what that changes, what it preserves, and where the result can stop working once it is copied, shared or loaded somewhere else. It is based on documented format rules and general parser behavior. No specific converter, website or destination application was tested for this article, so claims about particular tools are left out.
Is the conversion right for your use?
JSONL suits record-oriented data that a machine reads one record at a time. Common examples are log streams, dataset exports, bulk-import files and batch job inputs. Its main benefit is that a reader can parse and act on each line without loading the whole file. That keeps memory use flat, lets you append records without rewriting the file, and lets line-based tools such as split, head, wc -l and grep work on records directly.
The key tradeoff is that a JSONL file is no longer a single valid JSON document. A standard JSON parser will reject it, and any program expecting one array or object will fail or read only part of it. Long single-line records are also harder for people to scan than indented JSON.
Keep a regular JSON document, pretty-printed if people read it, in these cases:
- The data is a configuration file or a single structured object rather than a set of records.
- An API, schema validator or application expects one JSON document.
- The dataset is small enough that streaming offers no practical gain.
- People will review, diff or hand-edit the content, where indentation helps more than line-per-record layout.
What the conversion changes
This is a formatting and framing change. It does not add or remove data. A converter typically parses the input, takes each element of the top-level array, writes that element as compact JSON with no internal line breaks, and ends it with a newline character. The stored characters really do change: indentation and insignificant whitespace are removed, and the array brackets and separating commas disappear. This is not a display effect such as CSS wrapping or an editor's view setting. The file on disk is different.
An illustrative input:
[
{"id": 1, "name": "Ana", "tags": ["a", "b"]},
{"id": 2, "name": "José 👋", "note": "line one\nline two"}
]
The corresponding JSON Lines output, as produced by the jq command shown later:
{"id":1,"name":"Ana","tags":["a","b"]}
{"id":2,"name":"José 👋","note":"line one\nline two"}
Some details in this example are worth checking:
- Nested arrays and objects stay nested inside their line. Conversion does not flatten them.
- The line break inside the note value was already stored as the two-character escape \n, so it stays escaped and does not split the record across lines. A correct JSON serializer always escapes raw newlines in strings this way.
- Characters are not reordered or recombined. The accented é and the multi-code-point emoji pass through unchanged as UTF-8.
- Some tools write non-ASCII characters as escapes instead. For example, Python's json.dumps with its default settings writes José 👋 as Jos\u00e9 \ud83d\udc4b, with the emoji stored as a surrogate pair. The bytes differ, but any compliant parser reads back the same string.
The word 'convert' can mean different things depending on the input:
- A top-level array is the clear case: one element per line.
- A top-level object is ambiguous. Some tools write the whole object as one line. Others write one line per key or per value. Check which behavior a tool uses before trusting the output.
- JSONL, JSON Lines and NDJSON (newline-delimited JSON) describe essentially the same layout. Destinations may still differ on details such as accepted file extensions, blank lines or the required content type.
The JSON Lines convention specifies UTF-8 text, one valid JSON value per line, and a newline as the line terminator. It suggests the .jsonl extension. Each line may be any JSON value, though in practice most consumers expect objects.
What can be lost if the converter parses and re-serializes
Most converters decode the JSON into the host language's data structures and then encode it again. That round trip is where meaning can change:
- Large integers: JavaScript-based tools store numbers as 64-bit floats, so integers beyond 2^53 can be silently rounded. IDs and timestamps are typical victims. Python's json module keeps integers exact.
- Number formatting: values such as 1.0 or 1e3 may be rewritten in a different but numerically equal form, which matters if something downstream compares text rather than values.
- Duplicate keys: JSON does not define their behavior. Many parsers keep only the last occurrence, so duplicates can vanish.
- Key order: JSON objects are formally unordered. Most common tools preserve order, but nothing in the standard guarantees it.
If any of these matter for your data, compare record counts and sample values before and after converting. Prefer a tool whose number handling you can confirm.
Will the result stay usable after copying or sharing?
Each line in JSONL is a record boundary, so anything that alters line breaks can corrupt the file. Watch for these risks when moving JSONL between systems:
- Line endings: Windows-style CRLF endings are usually tolerated, because JSON parsers ignore trailing whitespace. Strict or hand-written readers may not tolerate them.
- Pasting into chat apps, word processors or email: these can wrap long lines and insert real line breaks, replace straight quotes with curly quotes, or drop trailing newlines. Any of these produces invalid records. Share JSONL as a file attachment rather than pasted text.
- Byte order mark: a UTF-8 BOM at the start of the file can make the first line fail to parse in some readers.
- Blank lines and a missing final newline: consumers differ on whether these are acceptable.
- Editing: soft wrapping in an editor is only a display effect and is harmless. A hard line break inserted inside a record splits it into two invalid lines.
Accessibility and search: compact single-line records offer no indentation cues, so very long lines are harder to read in a text editor or with a screen reader. No assistive technology was tested for this article, so specific behavior cannot be stated. If people need to read or review the data, provide a pretty-printed JSON copy or a table export alongside the JSONL file. The upside is that line-based search finds whole records: grep returns the complete matching record, which a multi-line JSON document cannot offer.
Destination limits: requirements of specific import tools, data platforms and model-training services were not verified here. Check each destination's own documentation for its encoding, maximum line length, blank-line handling and expected file extension. One successful load in one place does not show the file will work everywhere.
Converting locally
Browser-based converters are convenient, but their appearance or marketing tells you nothing about whether uploaded data is logged or kept. For sensitive or regulated data, read the tool's published privacy terms or convert locally. With jq installed, this command writes each element of a top-level array as one compact line:
jq -c '.[]' input.json > output.jsonl
A Python equivalent that keeps non-ASCII characters readable and forces newline line endings:
import json
with open("input.json", encoding="utf-8") as f:
records = json.load(f)
with open("output.jsonl", "w", encoding="utf-8", newline="\n") as out:
for record in records:
out.write(json.dumps(record, ensure_ascii=False) + "\n")
Both approaches load the entire input into memory first. That is fine for typical files, but for very large arrays you will need a streaming parser. To turn JSONL back into a single JSON array, jq can read all the lines into one array with jq -s '.' input.jsonl > output.json.
Bottom line
Converting JSON to JSONL preserves the data when the input is a top-level array and the converter handles numbers and encoding carefully. Use it when software processes records one at a time. Keep standard JSON when a single document is expected, when the data is small, or when people need to read it. When sharing JSONL, send it as a file, not pasted text. Before relying on a converter or destination, check its handling of top-level objects, large numbers and line endings, because those points vary by tool and were not tested here.