JSONL vs JSON: when to use each
Published 2026-09-10 · FileType Converters engineering
JSON stores one complete JSON value, often an object or array. JSONL, also called NDJSON, stores one valid JSON value per line, usually one record per line. Use JSON for structured documents and APIs; use JSONL for logs, streaming exports, large datasets, and append-friendly processing.
Document shape
A normal JSON file must parse as one JSON value. For tabular data, that value is often an array of objects: [ {"id": 1}, {"id": 2} ]. The reader usually needs the complete syntax to be valid before it can parse the document.
A JSONL file contains separate JSON values separated by newlines: one object, array, string, or other JSON value per line. In practice, most JSONL datasets use one object per line. The file as a whole is not a single JSON array unless a tool treats it specially.
Why JSONL is used for logs and exports
JSONL is easy to append. A service can write one event at a time without reopening a large array and adding commas. A downstream processor can read line by line, recover after a bad line, and split files by byte ranges more easily than with one giant JSON document.
This is why JSONL appears in model training data, application logs, database exports, search indexes, and event pipelines. It favors streaming operations over document nesting.
Validation and common errors
The most common JSONL mistake is wrapping all rows in [ and ], which turns it back into JSON. The most common JSON mistake is concatenating objects with no array or commas, which is invalid JSON but may be valid JSONL if each object is on its own line.
Blank lines are another choice. Some parsers ignore them; stricter tools reject them because an empty line is not valid JSON. If you control the export, write exactly one JSON object per line and end the file with a final newline for Unix tooling.
Converting between them
JSON array to JSONL is straightforward when the array contains records. Each element becomes one line. JSONL to JSON wraps records in an array and inserts commas. Memory use can become an issue if a huge JSONL file is collected into one JSON array.
Nested data remains nested in either format. If the target is CSV, a separate flattening step is needed. Arrays, objects, and missing keys need explicit conventions before exporting to rows and columns.
Choosing for APIs and files
Use JSON for API responses, config files, and data documents where the whole structure matters. Use JSONL for streams, logs, queues, and bulk exports where records can be processed independently.
For spreadsheet users, neither JSON nor JSONL is ideal unless the structure is flat. Convert to CSV or XLSX after deciding which nested fields should become columns.
Operational checklist
File size changes the best choice. A small settings file should be one JSON document because it is easier to validate as a whole. A multi-gigabyte event export should usually be JSONL because tools can stream, split, compress, and retry record by record.
For command-line processing, JSONL also fits Unix text habits. You can sample with head, count lines with wc -l, and process batches without parsing the entire dataset. That convenience depends on the rule that records do not contain literal unescaped newlines outside JSON strings.
Compression works well with both formats, but access patterns differ. A compressed JSONL file can still be processed as records when the tool streams decompression. A compressed JSON array still has to respect the single-document grammar during parsing.
Final checks
A final export contract should name the format explicitly as JSON or JSONL. Many failures come from a producer sending newline-delimited records to a consumer that expected one array, or the reverse.
Questions
Is JSONL valid JSON?
A JSONL file with multiple lines is usually not one valid JSON document. Each individual line should be valid JSON.
What is NDJSON?
NDJSON means newline-delimited JSON. In common use it is the same idea as JSONL: one JSON value per line.
Can JSONL contain arrays?
Each line can be any valid JSON value, including an array, but most data workflows expect one object per line.