Skip to content
shellhacks.dev
Tooling

NDJSON to JSON Converter

Convert newline-delimited JSON (NDJSON, JSON Lines) to a JSON array and back, with every invalid line reported by its line number.

Free · No sign-up · Your inputs stay in your browser

Input

Convert JSON Lines (NDJSON) to a JSON array and back

Output

JSON array

3 records

Blank lines are skipped and a bad line is reported by number. Each line is parsed on its own, which is the point of the format: a log shipper, jq -c or a bulk API can stream it without holding the whole file.

Runs in this browser. Nothing you paste is sent to a server.

Why logs and bulk APIs use it

A JSON array has to be read to its closing bracket before it is valid; a file of one JSON value per line can be streamed, appended to and split anywhere. That is why structured logs, the Elasticsearch and OpenSearch _bulk API, BigQuery loads and many data exports use it. The format is specified at jsonlines.org.

In a terminal

jq -s . file.ndjson slurps lines into an array, and jq -c '.[]' file.json writes an array out one element per line. Both stream through files larger than a browser tab can hold.

Share

Frequently asked questions

What is the difference between NDJSON and JSON Lines?
None that matters: both are one JSON value per line, separated by newlines, in UTF-8. The names come from two specifications written independently.
Can a line contain a newline?
Not a raw one. Newlines inside strings are written as an escape sequence (a backslash and n), which every JSON encoder does when it writes compact output.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Go deeper

Suggested reading

Keep planning

Similar tools