JSONL to JSON converter
Paste JSON Lines (JSONL or NDJSON) or open a .jsonl file to get one JSON array. Paste an array to get one line per item. The file is read in your browser and never uploaded.
JSON Lines
JSON array
What a JSON Lines file looks like
A JSON Lines file has one JSON value per line, usually an object. There are no commas between the lines and no brackets around them. .jsonl and .ndjson are two names for the same format.
{"event_id":9007199254740993,"robot":"TIDY-001","event":"docked"}
{"event_id":9007199254740994,"robot":"TIDY-002","event":"stuck","stuck_under":"standing desk"}
{"event_id":9007199254740995,"robot":"TIDY-003","event":"run_finished","dust_g":412.50}[
{
"event_id": 9007199254740993,
"robot": "TIDY-001",
"event": "docked"
},
{
"event_id": 9007199254740994,
"robot": "TIDY-002",
"event": "stuck",
"stuck_under": "standing desk"
},
{
"event_id": 9007199254740995,
"robot": "TIDY-003",
"event": "run_finished",
"dust_g": 412.50
}
]The event IDs are above 9007199254740991, the largest integer JavaScript stores exactly, and 412.50 ends in a zero. Both come out as written, because values are copied as text. Untick Indent to keep each record on one line inside the array.
Structured loggers such as pino write this format, and so do Docker’s json-file log driver, BigQuery exports and jq -c. OpenAI’s fine-tuning and batch endpoints take it as input. A program can add a record by appending a line, and a reader can handle one line at a time without loading the whole file.
Why JSON.parse and json.load fail on a .jsonl file
Both expect the whole text to be one JSON value. They read the first line, find a complete object, and then reach the { that starts line 2, which is position 66 in the three lines above. Node.js reports Unexpected non-whitespace character after JSON at position 66 and Python reports JSONDecodeError: Extra data: line 2 column 1 (char 66). The guide to JSONDecodeError: Extra data covers the other causes of that message.
Lines that aren’t valid JSON
Lines that fail to parse are highlighted in the input and listed under the editors with the parser’s message. Click a line number to jump to that line. The result appears once the lines are fixed. To leave them out instead, press Convert the rest. The count under the editors then says how many lines were skipped.
Typical causes are a last line cut short when the program writing the log was stopped, a plain-text message or stack trace in the middle of a log, and lines written with Python’s print(record), which uses single quotes.
Input that isn’t one value per line is read too: objects pretty-printed one after another, which is what jq . prints for a .jsonl file, values run together like {"a":1}{"b":2}, and lines that still end with the commas they had inside an array. Each complete value becomes one record.
JSON Lines in JavaScript, Python and jq
JavaScript (Node.js)
import { readFileSync, writeFileSync } from "node:fs";
// events.jsonl -> events.json
const events = readFileSync("events.jsonl", "utf8")
.split("\n")
.filter(line => line.trim())
.map(line => JSON.parse(line));
writeFileSync("events.json", JSON.stringify(events, null, 2));
// events.json -> events.jsonl
const list = JSON.parse(readFileSync("events.json", "utf8"));
writeFileSync("events.jsonl", list.map(item => JSON.stringify(item)).join("\n") + "\n");Python
import json
# events.jsonl -> events.json
with open("events.jsonl", encoding="utf-8") as f:
events = [json.loads(line) for line in f if line.strip()]
with open("events.json", "w", encoding="utf-8") as f:
json.dump(events, f, indent=2)
# events.json -> events.jsonl
with open("events.json", encoding="utf-8") as f:
events = json.load(f)
with open("events.jsonl", "w", encoding="utf-8") as f:
for event in events:
f.write(json.dumps(event) + "\n")jq
# events.jsonl -> events.json
jq -s . events.jsonl > events.json
# events.json -> events.jsonl
jq -c '.[]' events.json > events.jsonlWith the three lines above, the JavaScript version writes the first event ID back as 9007199254740992 and the third as 9007199254740996. Python keeps the IDs. Both write 412.50 as 412.5. jq 1.7 leaves all three lines as they were.
Files can be up to 2 MB. For a larger file, use the jq commands above. Blank lines are skipped. JSON to JSONL needs an array at the top level, so if your list sits inside an object such as {"events": [...]}, paste the array on its own. Open in viewer sends the records to the JSON viewer, where the Table tab shows one row per record.