Skip to content
Web Technologies

JSONL vs JSON: Differences and When to Use Each

Pim

Pim · Scrappey Research

October 29, 2026 3 min read

On this page

JSON stores one document, usually an array or object, while JSONL (JSON Lines) stores one complete JSON value per line. A JSON file has to be read as a whole before you can use it. A JSONL file can be read, written, and appended one line at a time, which makes it the usual format for logs, large exports, and scraped records. JSONL is also called newline-delimited JSON (NDJSON); the two names describe the same format.

Quick facts

File extension.json vs .jsonl (also .ndjson)
StructureOne document vs one JSON value per line
StreamingJSON: parse the whole file · JSONL: line by line
AppendingJSONL: add a line · JSON: rewrite the file
Common uses of JSONLLogs, data exports, ML datasets, bulk APIs

The same data in both formats

Three scraped products as a JSON array:

[
  {"name": "Desk lamp", "price": 24.99},
  {"name": "Office chair", "price": 149.00},
  {"name": "Monitor arm", "price": 39.50}
]

The same three records as JSONL. There are no brackets and no commas between records; each line is a complete JSON object:

{"name": "Desk lamp", "price": 24.99}
{"name": "Office chair", "price": 149.00}
{"name": "Monitor arm", "price": 39.50}

The rules are short: the file is UTF-8, every line is one valid JSON value, and lines are separated by \n. A line can't be pretty-printed across several lines, because a line break ends the record.

When to use JSONL and when to use JSON

Use JSONL when:

  • The data is a long list of similar records, such as scraped items, log events, or rows from a database export.
  • You write records as they arrive. A scraper can append one line per page, and a crash only loses the line being written, not the whole file.
  • The file is too large to load into memory. You can process it line by line, or split it with standard tools like head, split, and wc -l.
  • A tool expects it. The OpenAI Batch API and fine-tuning uploads, BigQuery's newline-delimited JSON loads, and the Elasticsearch _bulk API all take this format.

Use JSON when:

  • The data is one document with nested structure, such as a config file or a single API response.
  • You return a response from a web API. Clients expect one parseable body.
  • People will read or edit the file by hand, where pretty-printed JSON is easier to scan.

Reading, writing, and converting JSONL

In Python, write one json.dumps() per line and read the file line by line:

import json

records = [{"name": "Desk lamp", "price": 24.99}, {"name": "Office chair", "price": 149.00}]

# Write (or append with "a")
with open("products.jsonl", "w", encoding="utf-8") as f:
    for r in records:
        f.write(json.dumps(r, ensure_ascii=False) + "\n")

# Read one record at a time
with open("products.jsonl", encoding="utf-8") as f:
    for line in f:
        if line.strip():
            print(json.loads(line))

With pandas, pd.read_json("products.jsonl", lines=True) loads JSONL into a DataFrame, and df.to_json("out.jsonl", orient="records", lines=True) writes it back.

To convert on the command line with jq:

# JSON array -> JSONL
jq -c '.[]' products.json > products.jsonl

# JSONL -> JSON array
jq -s '.' products.jsonl > products.json

Scrapy writes JSONL directly when the output file ends in .jsonl, for example scrapy crawl products -o products.jsonl.

Related terms

Concept map

Concept map

How JSONL vs JSON: What's the Difference connects

The terms most directly tied to this one. Hover a node to see its neighbours, click to preview, drag to rearrange.

0 terms · 0 connections
You are here · Web Technologies
Building map…

Frequently asked questions

What is the difference between JSONL and JSON?

A JSON file holds one document, usually an array of records wrapped in brackets. A JSONL file holds one JSON value per line with no surrounding array, so it can be streamed, appended to, and processed line by line without loading the whole file.

Is JSONL the same as NDJSON?

Yes, for practical purposes. JSON Lines (.jsonl) and newline-delimited JSON (.ndjson) both mean one JSON value per line, separated by newlines. Tools that read one read the other.

Is a JSONL file valid JSON?

Not as a whole. Each line is valid JSON on its own, but a file with several lines is not a single JSON document, so a regular JSON parser rejects it. Parse it line by line, or convert it to an array first.

Which format is better for web scraping output?

JSONL, in most cases. A scraper can write each record as soon as it is extracted, a crash does not corrupt earlier records, and large result sets can be processed without loading everything into memory. Convert to a JSON array at the end if a downstream tool needs one.

Last updated: 2026-10-29