JSON to JSONL and back — convert arrays to JSON Lines (NDJSON)

Paste a JSON array to get JSON Lines, one compact record per line, or paste JSON Lines to get a single JSON array back; the direction is detected for you and a broken line is reported by its line number.

Live demo · real result from this tool

JSON Lines

{"id":1,"name":"Asha","city":"Pune","score":92.5,"active":true}{"id":2,"name":"Ben","city":"Leeds","score":78,"active":false}{"id":3,"name":"Chen","city":"Taipei","score":85.25,"active":true} 
Lines3

Processed on your device — nothing is uploaded.

How to use the JSONL converter

  1. Paste your data into JSON array or JSON Lines.
  2. Leave Convert on Detect automatically, or choose JSON array → JSONL or JSONL → JSON array.
  3. When producing an array, choose an Indent. JSON Lines output is always compact, one record per line.
  4. Copy or download the result. The count shows Lines written or Records read.

What it does and when to use it

JSON Lines is the format of choice when records are added one at a time or read as a stream: application logs, BigQuery exports, Elasticsearch bulk uploads, and training or evaluation files for machine-learning tools, which often ask for a .jsonl file with one example per line. Many tools that produce or expect these files are not the ones you use to edit data, so you often need to switch between the two shapes.

Turn a hand-written or exported array into a JSONL upload file, or turn a log excerpt into an array so you can query, sort or view it. After converting to an array, filter it with JSON query, view it with JSON to table, or check one record with the JSON validator.

How it works

Array to lines: the input is parsed, each item is written with JSON.stringify and no spaces, and the lines are joined with \n plus a final newline. Any string that contains a line break keeps it escaped as \n, so no record ever spans two lines. This matches the JSON Lines rules: UTF-8, one valid JSON value per line, newline as separator.

Lines to array: the text is split on line breaks, empty lines are skipped, and each line is parsed on its own. The first line that fails stops the conversion, and the message gives its line and column with the surrounding lines shown. All of it runs in your browser.

Worked examples

A two-item training file:

[
  {"prompt": "Capital of Kenya?", "completion": "Nairobi"},
  {"prompt": "2 + 2", "completion": "4"}
]
{"prompt":"Capital of Kenya?","completion":"Nairobi"}
{"prompt":"2 + 2","completion":"4"}

Two log lines with a blank line between them, converted with Indent set to none, give one array and Records: 2.

A missing brace on line 2 gives:

Invalid JSON Lines — line 2, column 1: Unexpected end of input — a closing } is missing.

Limits and tips

  • Array to JSONL needs a top-level array. A single object returns a message; wrap it in [ ].
  • Only the first bad line is reported. Fix it and run again to find the next one.

Frequently asked questions

Are JSONL, JSON Lines and NDJSON the same thing?
For practical purposes, yes. Each is UTF-8 text with one complete JSON value per line, separated by a newline. JSON Lines files usually end in .jsonl and NDJSON files in .ndjson. The download here is named data.jsonl.
How does Detect automatically decide the direction?
If the whole input parses as a single JSON array, it is converted to JSON Lines. Anything else is read as JSON Lines and converted to an array. So a file of several lines, each an array, still becomes an array of arrays. Choose the direction yourself if the guess is wrong.
What happens to blank lines?
They are skipped when reading JSON Lines, so a trailing newline or an empty line between records does not cause an error. Windows line endings (CRLF) are fine too.
Can a record span several lines?
No. In JSON Lines every record must sit on one line. A pretty-printed object split over several lines fails on its first line with an "end of input" error. Minify each record first, or paste the records as a JSON array and convert that.
Is there a size limit?
There is no fixed limit, but the whole text is held in the browser's memory at once. For very large logs, a streaming command-line tool such as jq is the better choice.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close