JSON to JSONL Converter

Turn a JSON array into JSON Lines (NDJSON): one compact record per line, converted locally in your browser.

What JSON Lines is

JSON Lines (also called JSONL or NDJSON, newline-delimited JSON) stores one complete JSON value per line, with no enclosing array and no commas between records. Because each line stands alone, a file can be streamed, appended to and split without parsing the whole thing, which is why data tools prefer it for large datasets.

How to convert JSON to JSONL

  1. Paste a JSON array into the Input box. The whole input must be one valid JSON document.
  2. Click Run Tool. Every array element is serialised as compact JSON on its own line, in the original order.
  3. Click Copy and save the result with a .jsonl or .ndjson extension.
  4. If an error appears instead, the input is not valid JSON; the message comes from the browser's parser. Fix it in the JSON validator, which shows the exact line and column.

Worked examples

1. A plain array of records

[{"id":1,"name":"Ada","tags":["x"]},{"id":2,"name":"Bo","ok":true}]

becomes

{"id":1,"name":"Ada","tags":["x"]}
{"id":2,"name":"Bo","ok":true}

Records keep their own keys; nothing forces them into a shared shape.

2. A fine-tuning dataset

Chat examples are usually written as an array while you edit them and uploaded as JSONL:

[
  {"messages": [
    {"role": "system", "content": "You are a terse SQL assistant."},
    {"role": "user", "content": "Count rows in orders"},
    {"role": "assistant", "content": "SELECT COUNT(*) FROM orders;"}
  ]},
  {"messages": [
    {"role": "user", "content": "Line one\nLine two"},
    {"role": "assistant", "content": "Got both lines."}
  ]}
]

becomes two lines, one training example each:

{"messages":[{"role":"system","content":"You are a terse SQL assistant."},{"role":"user","content":"Count rows in orders"},{"role":"assistant","content":"SELECT COUNT(*) FROM orders;"}]}
{"messages":[{"role":"user","content":"Line one\nLine two"},{"role":"assistant","content":"Got both lines."}]}

The line break inside the second user message stays escaped as \n, so a record never spans two lines.

3. An API response with a wrapper

Paging APIs often return the records inside an object:

{"data": [{"id": 1}, {"id": 2}], "next": null}

Because the top level is an object, the result is a single line:

{"data":[{"id":1},{"id":2}],"next":null}

To get one line per record, extract data first (in the jq playground the filter is .data) and convert that array.

Where JSONL is required

Edge cases to check

Before you upload a JSONL file

Loaders reject a whole file for one bad record, so a quick check saves a failed job. Convert the finished file back with JSONL to JSON: if it parses, every line is valid JSON. Open the resulting array in the JSON viewer and confirm each record has the keys the service expects, for example a messages list for chat fine-tuning or a custom_id for batch requests. Finally, estimate size and cost per example with the JSON token counter.

FAQ

Is JSONL the same as NDJSON?

For practical purposes, yes. Both mean one JSON value per line separated by \n; the files usually use the .jsonl or .ndjson extension and the application/x-ndjson media type.

Should the file end with a newline?

It is recommended but optional, and most readers accept both. The converter output stops after the last record, so add a final line break when you save the file if your loader or wc -l count expects one. Avoid blank lines in the middle, which some loaders reject.

What happens if I paste a single object instead of an array?

It is written as a one-line file containing that object. Only a top-level array is split into several lines.

Why is my whole response on one line?

The input was an object that wraps the array, such as {"data": [...]}. Extract the inner array first with the jq playground or JSONPath tester, then convert it.

Does it change my data?

No. Each element is re-serialised compactly, so whitespace inside records disappears, but keys, key order, values and Unicode text are kept. Line breaks inside strings stay escaped as \n.

How many tokens will my dataset use?

Paste a record into the JSON token counter to estimate the token count per example before uploading.