Paste a JSON array on the left to get one compact record per line.
Try it with two chat-style training records
Paste a JSON array on the left to get one compact record per line.
Try it with two chat-style training records
This JSON to JSONL converter turns a JSON array into JSON Lines in three steps, and the same tool converts JSONL back to JSON when you need the array again.
Paste your data into the left editor, or use the upload button to open a .json file. The JSON to JSONL conversion expects a JSON array. If you have a single object, it is written as a one-line file and the tool tells you so. Not sure the input is valid? You can validate the JSON first.
[
{
"messages": [
{
"role": "user",
"content": "What is JSONL?"
},
{
"role": "assistant",
"content": "One JSON value per line."
}
]
},
{
"messages": [
{
"role": "user",
"content": "Is NDJSON different?"
},
{
"role": "assistant",
"content": "No, same format."
}
]
}
]Every array element becomes one line of the output, in the original order, and the status bar shows how many records were written. Invalid JSON is reported with its position, and no half-finished output is shown. The sample on the right is the JSON to JSONL conversion of two chat-style training records.
{"messages":[{"role":"user","content":"What is JSONL?"},{"role":"assistant","content":"One JSON value per line."}]}
{"messages":[{"role":"user","content":"Is NDJSON different?"},{"role":"assistant","content":"No, same format."}]}When the JSON to JSONL conversion is done, copy the lines or download them as a .jsonl file. Each line is a compact JSON value and the file ends with a newline.
JSONL, JSON Lines and NDJSON (newline-delimited JSON) are three names for one text format. A file holds one complete JSON value per line, usually an object, and the lines are separated by a newline character. The encoding is UTF-8. A JSON to JSONL converter such as this one simply writes every element of your array on its own line.
A normal JSON file is one document, so a program must read all of it before it can use any record. A JSONL file can be read, filtered and appended to one record at a time, which suits logs, exports and datasets that are too large to hold in memory. Use plain JSON for API responses and configuration, and JSONL for streams of records.
\n (a \r\n ending is tolerated by most readers).\n, never as a real line break.Switch the direction to JSONL → JSON and paste or open your lines. Each non-empty line is parsed on its own, and the records are collected into one array with two-space indentation. Windows line endings and a leading byte order mark are handled, and blank lines are ignored.
If a line is not valid JSON, the converter stops at the first one and shows its line number, so you can fix exactly that record. Turn on Skip invalid lines if you would rather keep the valid records and see how many were left out. In this example the second line is missing its closing brace:
{"id":1,"event":"login"}
{"id":2,"event":"click"
{"id":3,"event":"logout"}The converter reports an error on line 2, and the empty third line is ignored.
Many language-model tools take training examples and batch requests as JSONL, one example per line. JSON to JSONL conversion is often the step that prepares them, and this converter only changes the format. Check the required fields and file limits against the documentation of the platform you upload to.
Warehouses such as BigQuery can load newline-delimited JSON, so a quick JSON to JSONL conversion of an exported array is often the first step of an import.
JSON to JSONL conversion also suits logs: because each line stands alone, log shippers and stream processors can append new records without rewriting the file, and a broken line only affects that one record.
If you prefer the terminal, these commands do the same JSON to JSONL conversion and its reverse:
# JSON array -> JSONL
jq -c '.[]' in.json > out.jsonl
# JSONL -> JSON array
jq -s . in.jsonl > out.json# Python: JSON array -> JSONL and back
import json
with open("in.json", encoding="utf-8") as src, open("out.jsonl", "w", encoding="utf-8") as dst:
for record in json.load(src):
dst.write(json.dumps(record, ensure_ascii=False) + "\n")
with open("out.jsonl", encoding="utf-8") as src:
records = [json.loads(line) for line in src if line.strip()]
with open("back.json", "w", encoding="utf-8") as dst:
json.dump(records, dst, ensure_ascii=False, indent=2)Common questions about JSON Lines, NDJSON and converting between JSON and JSONL
Edit, format, and beautify JSON
Validate, fix, and inspect JSON
Compare, measure, and map JSON
Convert JSON to other formats
Convert other formats to JSON
Convert, format, fix, and minify XML
Generate code and format other languages