Ctrl + K
JSON11 min read

JSON Lines (JSONL) Explained

Understand the JSON Lines format, its structure, advantages, limitations and common use cases for processing structured data.

Published: 2026-09-02

JSON Lines, commonly abbreviated as JSONL, is a text format where each line contains one complete JSON value, usually a JSON object. Instead of storing an entire collection inside one JSON array, JSON Lines represents records independently, making the format convenient for logs, data pipelines, command-line processing and streaming applications.

JSONL is closely related to Newline Delimited JSON (NDJSON). In practical usage, the two terms are often treated as interchangeable because both describe data represented as individual JSON values separated by newline characters. The main idea is simple: one line represents one record, and each record must be valid JSON on its own.

What Is JSON Lines?

JSON Lines is a line-oriented format for storing multiple JSON values in a single text file or stream. Each line is parsed independently, which means applications can process records one at a time instead of loading the entire dataset into memory.

{"id":1,"name":"Alice"}
{"id":2,"name":"Bob"}
{"id":3,"name":"Charlie"}

The example contains three separate JSON objects. They are not wrapped in an outer array, and each object occupies its own line.

How JSONL Differs from Regular JSON

A regular JSON document commonly represents a complete structure such as an object or array. When multiple records are stored together, they are often placed inside an array. JSONL removes the need for that surrounding array and treats every line as an independent JSON value.

CharacteristicJSONJSONL
Multiple recordsUsually stored in an arrayOne record per line
Outer array requiredOftenNo
Independent parsingLess convenientNatural
StreamingMore difficult for large arraysWell suited
Human readabilityGoodGood for line-oriented data

Basic JSONL Structure

Each line must contain a complete JSON value. In most data-processing applications, these values are objects containing fields that represent one record. Newline characters separate records rather than acting as whitespace inside one large JSON structure.

{"timestamp":"2026-08-24T10:00:00Z","level":"info","message":"Server started"}
{"timestamp":"2026-08-24T10:01:12Z","level":"error","message":"Connection failed"}
💡 Keep each JSONL record self-contained. A parser should be able to read one complete line without needing information from the previous or next line.

JSONL Records Can Have Different Fields

JSONL does not require every object to contain exactly the same fields. Records can have different structures as long as each individual line is valid JSON. However, consistent schemas are usually easier to process and validate in structured data pipelines.

{"id":1,"name":"Alice"}
{"id":2,"name":"Bob","active":true}
{"id":3,"name":"Charlie","role":"admin"}

JSONL and JSON Arrays

The same logical records can be represented either as a JSON array or as JSONL. A JSON array creates one complete JSON document, while JSONL creates a sequence of independent JSON values.

[
  {"id":1,"name":"Alice"},
  {"id":2,"name":"Bob"},
  {"id":3,"name":"Charlie"}
]
{"id":1,"name":"Alice"}
{"id":2,"name":"Bob"}
{"id":3,"name":"Charlie"}

The JSON array is a single document containing three objects. The JSONL version contains three independently parseable records. This distinction becomes especially useful when datasets become large or when records need to be processed as they arrive.

JSONL and NDJSON

JSON Lines and NDJSON describe essentially the same line-delimited approach to JSON data. JSONL is commonly used as a filename extension and informal format name, while NDJSON is frequently used in technical documentation and data-processing systems. The exact terminology can vary between tools and projects.

TermTypical Meaning
JSONLJSON values separated by newlines
NDJSONNewline Delimited JSON
.jsonlCommon file extension for JSON Lines files
.ndjsonCommon file extension for NDJSON files

Why JSONL Is Useful for Large Datasets

One of the main advantages of JSONL is that records can be processed incrementally. An application can read a line, parse it, process the resulting object and then move to the next line. It does not necessarily need to load an entire dataset into memory first.

This approach is particularly useful for large logs, exports, machine-learning datasets and data-processing pipelines. A program can also append new records to the end of a JSONL file without rewriting an enclosing JSON array.

Streaming JSONL Data

Because records are independent, JSONL works naturally with streaming systems. A producer can emit one JSON object at a time while a consumer reads and processes each record as it becomes available.

Producer → JSONL stream → Reader → Parse one line → Process record

This design can reduce memory usage and allows processing to begin before the complete dataset has been received.

JSONL for Application Logs

JSONL is particularly convenient for structured application logs. Each log entry can contain fields such as a timestamp, severity level, request identifier, message and additional metadata. Log processors can then read each line independently.

{"level":"info","message":"Request received","status":200}
{"level":"warn","message":"Slow response","status":200,"durationMs":1450}
{"level":"error","message":"Database unavailable","status":503}

JSONL for Data Pipelines

Data pipelines often transform information from one system into another. JSONL is useful as an intermediate format because individual records can be read, transformed and written independently. This makes it convenient for batch processing as well as incremental workflows.

  • Export records from a database.
  • Transform each record independently.
  • Filter records based on selected fields.
  • Send records to another processing system.
  • Store the transformed output as JSONL.

JSONL for Machine Learning Data

JSONL is commonly used for datasets in which each training or evaluation example is represented as one JSON object. Independent records make it convenient to generate, inspect, filter and process large collections without requiring one massive JSON document.

{"prompt":"What is JSON?","answer":"JSON is a lightweight data interchange format."}
{"prompt":"What is JSONL?","answer":"JSONL stores one JSON value per line."}

Appending Data to JSONL

Appending records is straightforward because a JSONL file does not need to maintain an outer array or update closing brackets. A new valid JSON value can simply be written on a new line.

{"id":1,"status":"complete"}
{"id":2,"status":"complete"}
{"id":3,"status":"pending"}

This property can make JSONL convenient for logs and incremental exports where new records are continuously added over time.

Parsing JSONL

A basic JSONL parser reads the input one line at a time, removes the line terminator, parses the line as JSON and handles the resulting value. Blank lines and malformed records should be handled according to the requirements of the application.

const records = jsonl
  .split("\n")
  .filter(Boolean)
  .map((line) => JSON.parse(line));
⚠️ Do not parse a JSONL file as one ordinary JSON document. Multiple top-level JSON objects separated only by newlines are not a single valid JSON document.

Handling Invalid JSONL Records

A single malformed line can cause a straightforward parser to fail if errors are not handled individually. Robust applications should decide whether to reject the complete file, skip invalid records, report errors, or preserve the original input for later investigation.

  • Validate each line independently.
  • Report the line number when parsing fails.
  • Avoid silently discarding malformed records.
  • Keep error handling separate from normal record processing.
  • Define whether partial processing is acceptable.

Newlines Inside JSON Strings

A JSONL record must remain one physical line in the file. JSON strings can represent line breaks using escaped characters such as \n, but an actual unescaped newline inside a JSON string would break the line-oriented structure and make the record invalid.

{"message":"First line\nSecond line"}

Advantages of JSONL

  • Easy to process one record at a time.
  • Well suited to streaming workflows.
  • Convenient for large datasets.
  • Easy to append new records.
  • Works well with command-line tools.
  • Each record can be validated independently.

Limitations of JSONL

  • The complete file is not one standard JSON document.
  • Multiline formatting is inconvenient.
  • Records may become inconsistent without schema validation.
  • Malformed lines require careful error handling.
  • Random access to records usually requires additional indexing.

JSONL vs CSV

JSONL and CSV are both useful for line-oriented data, but they represent records differently. CSV is compact and convenient for simple tabular data, while JSONL handles nested objects, arrays and varying record structures much more naturally.

FeatureJSONLCSV
Nested dataSupportedLimited
Schema flexibilityHighLower
Human readabilityGoodVery good for tables
Streaming recordsYesYes
Simple tabular dataGoodExcellent

When Should You Use JSONL?

JSONL is a strong choice when data consists of independent records and those records need to be processed incrementally. It is especially useful for logs, large exports, streaming pipelines, machine-learning datasets and command-line workflows.

Use CaseJSONL Suitability
Application logsExcellent
Large record exportsExcellent
Streaming dataExcellent
Machine-learning datasetsExcellent
Simple configuration filesUsually unnecessary
Small nested configurationRegular JSON may be better
💡 Choose JSONL when the natural unit of processing is an individual record. Choose regular JSON when you need one complete hierarchical document.

Common JSONL Mistakes

Most JSONL problems come from treating the format like an ordinary JSON document or from producing lines that are not independently valid JSON. Small formatting mistakes can prevent parsers and data-processing tools from reading the file correctly.

  • Wrapping JSONL records in an unnecessary outer array.
  • Writing multiple objects on one line.
  • Using trailing commas between records.
  • Including unescaped newline characters inside JSON strings.
  • Ignoring malformed records during processing.
  • Assuming every JSON parser automatically supports JSONL.

Best Practices

  • Keep exactly one complete JSON value per line.
  • Use consistent field names and data types when possible.
  • Validate records before processing or exporting them.
  • Handle malformed lines explicitly.
  • Use UTF-8 consistently across the pipeline.
  • Choose JSONL for record-oriented data rather than hierarchical documents.
💡 For production data pipelines, combine JSONL with schema validation when consistent record structure is important.

Frequently Asked Questions

What is JSONL?

JSONL, or JSON Lines, is a format where each line contains one complete JSON value, typically a JSON object. Records are separated by newline characters and can be processed independently.

Is JSONL the same as NDJSON?

JSONL and NDJSON generally describe the same newline-delimited JSON approach. The terminology and file extensions vary between tools and projects.

What is the difference between JSON and JSONL?

Regular JSON represents one complete JSON document, while JSONL stores multiple independent JSON values with one value per line.

Can JSONL contain arrays?

Yes. Each JSONL line can contain any valid JSON value, including an object, array, string, number, boolean or null. In most data-processing use cases, objects are used as records.

Why is JSONL useful for large files?

JSONL can be processed one record at a time, reducing the need to load an entire dataset into memory and making the format well suited to streaming and incremental processing.

Can JSONL be appended to?

Yes. New records can normally be added as new lines without rewriting an outer JSON array, which makes JSONL convenient for logs and incremental data exports.

Helpful JSON Tools

A JSON Lines Formatter helps format JSONL records into a readable line-oriented structure, a JSON Lines Validator checks whether individual lines contain valid JSON, an NDJSON Viewer makes newline-delimited records easier to inspect, an NDJSON to JSON Converter transforms JSONL or NDJSON records into standard JSON structures, and a JSON Formatter formats ordinary JSON documents for easier reading and debugging.

Conclusion

JSON Lines provides a simple way to store and process independent JSON records without wrapping them in one large document. Its one-record-per-line structure makes it especially useful for logs, streaming systems, large datasets, machine-learning workflows and data pipelines. Although regular JSON remains a better choice for many hierarchical documents and configuration files, JSONL is often the more practical format when records need to be processed incrementally, appended efficiently or handled independently.

Found an issue?

Found an error, outdated information, or something missing from this article? Let me know through the Contact page.

Your feedback helps improve our articles and keep them accurate and useful.