Xerobit

NDJSON to JSON Converter

Convert NDJSON (Newline Delimited JSON) into a standard JSON array by pasting your text below. Each line becomes an element in the resulting array, with optional pretty-printing. The conversion runs entirely in your browser, so nothing is uploaded to any server.

One valid JSON value per line.

Result

[]

How to use the ndjson to json converter

  1. Paste your NDJSON text into the input area, ensuring each line contains one complete JSON value.
  2. Toggle Pretty print output if you want the resulting array indented for readability.
  3. The converted JSON array appears immediately below as you type or paste.
  4. Copy the result to use in your application, API response, or data pipeline.

What is NDJSON?

NDJSON stands for Newline Delimited JSON. It is a text format where each line is a separate, self-contained JSON value. Unlike a standard JSON file that wraps everything in a single root object or array, NDJSON streams values one per line. This makes it ideal for appending log entries, streaming large datasets, and processing records sequentially without loading an entire file into memory.

A valid NDJSON file might look like this:

{"id":1,"status":"ok"}
{"id":2,"status":"fail"}
{"id":3,"status":"ok"}

Each line parses independently. Empty lines are typically ignored during conversion.

How the conversion works

The ndjson to json conversion follows a straightforward algorithm. First, the input text is split on newline characters (\n or \r\n). Blank lines are discarded. Then, each remaining line is parsed individually using a standard JSON parser. If any line fails to parse, the tool reports the exact line number and error message. Finally, all successfully parsed values are collected into a single JSON array.

For example, given three lines containing 1, "two", and [3], the parser produces the array [1, "two", [3]]. The optional pretty-print step then applies indentation (two spaces per level) to make the output human-readable.

Common use cases

Converting NDJSON to a JSON array is frequently needed when moving data between systems that expect different formats. Here are typical scenarios:

  • API responses: Some services stream results as newline-delimited JSON. Wrapping them in an array makes them compatible with clients expecting standard JSON.
  • Log analysis: Structured logs from tools like Winston or Bunyan are often written in NDJSON. Converting them to an array allows easy filtering and transformation.
  • Data import: Databases and analytics tools sometimes require a single JSON array rather than a stream of objects.

If your source data is in other structured formats, sibling converters like TSV to JSON, TOML to JSON, or INI to JSON handle those transformations before you reach the JSON stage.

Edge cases and pitfalls

Several edge cases can trip up a naive ndjson to json converter:

  • Trailing newlines: Files often end with a newline character, producing an empty final line. A robust converter skips empty lines rather than throwing a parse error.
  • Mixed value types: NDJSON does not require every line to be an object. Lines can contain strings, numbers, booleans, null, or arrays. The resulting JSON array will hold mixed types, which is perfectly valid JSON but may surprise downstream consumers expecting uniform objects.
  • Large files: Because this tool collects all values into a single array in memory, extremely large NDJSON inputs (millions of lines) may cause the browser tab to slow down. For massive datasets, consider command-line tools like jq.
  • Invalid JSON on one line: A single malformed line prevents the entire conversion. The error message identifies the offending line number so you can fix it quickly.

NDJSON vs JSON Lines

You may encounter the terms NDJSON and JSON Lines used interchangeably. Both describe the same concept: one JSON value per line, separated by newline characters. The JSON Lines specification (.jsonl extension) formalizes what NDJSON describes. In practice, any tool that reads NDJSON also reads JSON Lines and vice versa. When converting either format to a standard JSON array, the process is identical.

FeatureNDJSON / JSON LinesStandard JSON Array
Root structureNone (stream of values)Single array [...]
Append-friendlyYes, just add a lineNo, must rewrite brackets
Streaming parseYes, line by lineNo, needs full document
File extension.ndjson or .jsonl.json

Worked examples

ExampleInputResult
Two user objectsNDJSON input: {"name":"Alice","age":30} / {"name":"Bob","age":25}; Pretty print output: yes[ / { / "name": "Alice", / "age": 30 / }, / { / "name": "Bob", / "age": 25 / } / ]
Mixed typesNDJSON input: 42 / "hello" / true / null / [1,2,3]; Pretty print output: no[42,"hello",true,null,[1,2,3]]
Log entriesNDJSON input: {"level":"info","msg":"started"} / {"level":"error","msg":"failed"}; Pretty print output: yes[ / { / "level": "info", / "msg": "started" / }, / { / "level": "error", / "msg": "failed" / } / ]

FAQ

What is the difference between NDJSON and regular JSON?

Regular JSON requires a single root value, usually an object or array. NDJSON has no root wrapper; instead, each line is an independent JSON value. This makes NDJSON better suited for streaming and appending data.

Can I convert NDJSON with mixed types to JSON?

Yes. Each line is parsed independently, so your NDJSON can contain objects, arrays, strings, numbers, booleans, and null values. They will all be placed into a single JSON array.

Why does my conversion fail with a parse error?

Every non-empty line must be valid JSON. Common mistakes include trailing commas, single quotes instead of double quotes, or unquoted property names. The error message shows which line caused the failure.

Is my data sent to a server during conversion?

No. The ndjson to json conversion happens entirely in your browser using JavaScript. Nothing is uploaded anywhere, making it safe for sensitive or private data.

How do I convert NDJSON using command-line tools?

With jq, you can run jq -s '.' input.ndjson > output.json. The -s flag slurps all inputs into a single array. For very large files, this approach uses more memory than streaming.

Are empty lines allowed in NDJSON?

Strictly speaking, the NDJSON specification says each line must be valid JSON. However, most practical parsers, including this tool, skip blank lines gracefully to handle trailing newlines and formatting gaps.