"category": "format-converter",

JSON to JSON Lines Converter

"tldr": Paste a JSON array and get JSON Lines (NDJSON) - one compact object per line, the format logs, ML datasets, and streaming pipelines expect.

Convert a JSON array into JSON Lines (also called JSONL or NDJSON): each element serialized compactly onto its own line. This is the format expected by ML fine-tuning datasets, BigQuery and ClickHouse bulk loads, log processors, and every tool that streams records instead of loading whole documents.

{"json array": "json lines"}

JSON Lines exists because arrays do not stream or append: to add one record to a JSON array file you must rewrite the document, and to read one record you must parse everything before it. One-object-per-line fixes both - at the cost of no longer being a valid single JSON document, which is why converters like this exist for going back and forth.

How to convert JSON to JSON Lines

  1. 1Paste a JSON array of any values (objects are typical).
  2. 2Each element is minified onto its own line - no commas between lines, no wrapping brackets.
  3. 3Download as .jsonl for dataset uploads, or copy for your pipeline.
  4. 4Going the other way? Use our JSON Lines to JSON converter.

Convert JSON array to JSON Lines in code

Python
import json

with open("data.jsonl", "w") as f:
    for record in records:
        f.write(json.dumps(record) + "
")
JavaScript
const jsonl = records.map(r => JSON.stringify(r)).join("
");

Frequently asked questions

Is .jsonl the format OpenAI and other ML platforms want?

Yes - fine-tuning and batch APIs typically require JSONL: one training example per line. This converter produces exactly that shape from a normal JSON array; validate individual records against the platform schema separately.

Why do the lines have no commas between them?

Because JSONL is not a JSON array - it is a sequence of independent JSON documents separated by newlines. Commas would make every consumer fail. If you see commas in a .jsonl file, it is actually a broken JSON array.

What if my objects contain newlines in string values?

Safe - JSON serialization escapes newlines inside strings as \n, so each record still occupies exactly one physical line. That guarantee is what makes line-by-line processing possible.

Last updated:

You might also need

Free and in-browser, like everything on JSON Console. Browse all tools →