NDJSON to JSON Array Converter

Paste your NDJSON lines to merge them into one JSON array.

How it is calculated

The input is split into lines (Windows, Unix and old Mac line endings all work) and blank lines are ignored. Each remaining line is parsed on its own as one JSON value, and the parsed values are collected, in order, into one array, printed with four-space indentation and unescaped Unicode. The tool reports the number of lines converted and a valid flag. If any line is not valid JSON, no array is given: the NDJSON specification (3.2) says a parser should raise an error for such a line rather than pass over it, so the tool sets the flag to No and lists the line numbers that failed (the first 20), counting every line of the text, blank ones included. A line with the literal null is kept as null. Lines may hold objects, arrays, numbers or strings, and one line may not span several lines of text.

Worked example

Paste three lines: {"id":1,"name":"Ada"}, {"id":2,"name":"Linus"} and {"id":3,"name":"Grace"}. Each is a valid JSON object, so the tool puts them in a single array in the same order: an opening bracket, the three objects separated by commas, and a closing bracket. The line count shows 3 and the valid flag shows Yes. If the second line were damaged, say {"id":2,, the tool would give no array at all: the flag would be No and the error line would name line 2, so you can fix it and convert again.

Try this example →

Common mistakes

  • Pasting a pretty-printed or multi-line object. Each record must sit entirely on one line, otherwise the individual lines are not valid JSON and are dropped.
  • Hunting for the bad record by eye. The error line names the line numbers that did not parse; fix those and convert again.
  • Pasting a JSON array that is already complete. It is read as a single line and comes back wrapped in a second array, giving [[...]].
  • Trailing commas between lines. NDJSON lines are not separated by commas; a line ending in a comma is invalid and is skipped.
  • Using single quotes or unquoted keys, which are accepted by some tools but are not valid JSON and fail here.

Sources

About this calculator

NDJSON (Newline Delimited JSON, also called JSON Lines or .jsonl) stores one complete, self-contained JSON object per line instead of wrapping everything in a single top-level array. This format is popular for streaming and append-only data because a producer can write one record at a time without ever needing to rewrite the whole file, and a consumer can process it line by line without loading the entire dataset into memory.

Tools like Elasticsearch's bulk API, Fluentd and other log shippers, Spark and BigQuery data loaders, and many machine-learning dataset formats all emit or expect NDJSON. This converter parses each line as an independent JSON value and combines them into a single pretty-printed JSON array, which is the format most general-purpose JSON viewers, `jq` pipelines, and REST APIs expect when NDJSON isn't directly supported.

Was this helpful?

You can pick up to 3 reactions.

Note from the editors

A quick integrity check is built in: if any line fails to parse, the tool gives no array and names the failing line numbers instead of quietly leaving records out. Typical causes are a record wrapped over two lines or a stray trailing comma. Fix those at the source rather than in the output, since the tool repairs nothing. Where does your NDJSON come from: a database export, an API stream, or logs?

Comments

  • Be the first to comment.

Popular calculators

All Calculators