How to Turn NDJSON Log Lines into One JSON Array
JSON.parse fails on log files with one JSON object per line. How to wrap NDJSON / JSON Lines into a single array with the repair tool, in jq, Python and Node, and the limits of each.
Have broken JSON right now? Fix it free in under 1 second — no signup.
Fix My JSON →You copy a block of logs from your API gateway and paste it into JSON.parse:
{"ts":"2026-10-21T09:00:00Z","level":"info","route":"/api/orders","status":200,"ms":40}
{"ts":"2026-10-21T09:00:07Z","level":"info","route":"/api/users","status":200,"ms":77}
{"ts":"2026-10-21T09:00:14Z","level":"warn","route":"/api/checkout","status":429,"ms":114}
It fails on the second line: Unexpected non-whitespace character after JSON at position 88. Each line is valid JSON on its own, but a JSON document must contain exactly one value. This format is NDJSON (newline-delimited JSON), also called JSON Lines (.jsonl). To load it as one document, the lines have to become one array.
Step by step in the browser
- Paste all the lines into the repair tool — 200 lines or 20 000.
- Tap Fix My JSON. The tool sees several top-level values and wraps them into one array, with commas between them, in their original order.
- Check the report: it says how many values were wrapped. That number should equal your line count; if it is lower, a line was broken and was repaired or merged — read the rows below it.
- Copy or download the array. It now loads in any JSON tool,
pandas.read_json, a spreadsheet import, or the JSON to CSV guide.
The logs never leave your browser — useful when they carry user IDs or tokens.
The same thing in code
jq (slurp the lines into one array):jq -s '.' gateway.log > gateway.json
Python:
import json
with open("gateway.log") as f:
rows = [json.loads(line) for line in f if line.strip()]
json.dump(rows, open("gateway.json", "w"), indent=2)
Node:
const rows = fs.readFileSync('gateway.log', 'utf8').split('\n').filter(Boolean).map((l) => JSON.parse(l));
These are the right choice for files you process every day. Note that each of them stops on the first broken line; the repair tool is for the case where some lines are damaged and you still want the rest.
When to keep NDJSON instead
Do not convert if the consumer understands JSON Lines: streaming parsers, BigQuery and many log pipelines read NDJSON directly and can process it line by line without loading everything into memory. An array has to be read whole.
Limitations
- Everything becomes one array. The tool cannot group lines into separate documents or keep them as NDJSON; if you need NDJSON back, write each element on its own line after editing.
- A broken line is repaired by the same rules as any other JSON (missing quotes, trailing commas, truncation). Check the report rows when the wrapped count does not match your line count.
- Size. A few megabytes of logs repair in about a second; files in the tens of megabytes are better handled with
jq -sor a script. - Big integers (64-bit IDs, nanosecond timestamps) keep their digits in the output text, but JavaScript's
JSON.parserounds anything above 2^53 — keep such fields as strings downstream.
Related
Still dealing with broken JSON?
Paste it in and get it fixed in under 1 second — free, no signup, no install. Works with ChatGPT, Claude, n8n, and any AI output.
Fix My JSON Free →Related Articles