What Is JSON Lines (JSONL) Format?
JSON Lines — also written as JSONL or .jsonl — is a newline-delimited text format where
each line is a self-contained, valid JSON value. Unlike a standard JSON array, a JSONL file has no
outer wrapper: each row is independent, making it trivial to append records, stream data, or process
files in parallel without ever loading them fully into memory.
{"id":1,"event":"click","user":"alice"}
{"id":2,"event":"view","user":"bob"}
{"id":3,"event":"purchase","user":"carol"}
JSON Lines vs JSON — Key Differences
A standard JSON file is a single serialized value — usually an array or object. Every parser must read the whole file before it can yield a single record. By contrast, JSON Lines vs JSON comes down to one design principle: JSONL separates records with newlines instead of enclosing them in brackets, so a line-by-line reader can process record one while record ten million is still being written. This makes JSONL the natural choice for log ingestion pipelines, event streams, and large dataset exports.
When to prefer standard JSON
Use a regular JSON array when the dataset is small enough to fit comfortably in memory, when you need to share structured config with other services, or when the consumer does not support streaming reads.
When to prefer JSON Lines
JSONL shines for big-data pipelines (Spark, Hadoop, BigQuery), log aggregation (Elasticsearch, Loki), machine-learning dataset distribution, and any scenario where data is generated incrementally. JSONL also compresses extremely well with Gzip because repeated field names across lines create highly redundant patterns.
JSONL Format for OpenAI Fine-Tuning
The OpenAI fine-tuning API requires training data in JSONL format. Each line must be a JSON object
containing a messages array that follows the chat markup — system,
user, and assistant turns exactly as you would send them to
/v1/chat/completions:
{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"What is the capital of France?"},{"role":"assistant","content":"Paris."}]}
{"messages":[{"role":"system","content":"You are a helpful assistant."},{"role":"user","content":"Explain JSON Lines."},{"role":"assistant","content":"JSON Lines is a text format where each line is a valid JSON value..."}]}
Using the CSV → JSONL converter on this tool, you can import a spreadsheet of
prompt/response pairs and produce an OpenAI-ready .jsonl fine-tuning dataset in seconds.
The validator will then check every line and surface any malformed records before you upload.
How to Read JSON Lines Files
Because each line is independent JSON, reading JSONL is simple in every major language. The pattern is always the same: open the file, iterate line by line, and parse each line individually.
Python
import json
with open("data.jsonl") as f:
for line in f:
record = json.loads(line)
print(record)
Node.js
const fs = require("fs");
const rl = require("readline");
const stream = fs.createReadStream("data.jsonl");
const reader = rl.createInterface({ input: stream });
reader.on("line", line => {
const record = JSON.parse(line);
console.log(record);
});
jq (command line)
# Pretty-print all records jq '.' data.jsonl # Extract a specific field from every line jq '.user' data.jsonl
Convert CSV to JSONL
Converting a CSV spreadsheet to JSONL is a common data-engineering task, particularly when preparing
datasets for machine-learning pipelines or data warehouses. The first row of a valid CSV is treated
as the header, and each subsequent row is emitted as a JSON object keyed by those column names.
Our tool handles quoted fields, embedded commas, and empty cells automatically — just upload your
.csv file, choose CSV → JSONL, and download the result.
About This Tool
jsonlines.online runs on an Apache server with PHP for backend streaming. Inputs under 2 MB are
processed entirely in the browser — no data leaves your machine. Larger files are streamed through
PHP's fgets() loop, which means even a 500 MB JSONL log file is handled with a constant
memory footprint. All processing is ephemeral: uploaded files are deleted immediately after the
response is sent.