JSON Array to NDJSON Converter

Paste a JSON array to convert it to NDJSON, one value per line.

How it is calculated

The tool first checks that your text is valid JSON whose top level is an array. It then splits the array at the commas that sit outside any string, bracket or brace, removes the whitespace between tokens and writes each element on its own line, with no brackets around the whole list and no comma between lines. Each element keeps its original spelling: 1.0, 1e3, a very long integer and escapes such as \u00e9 are copied as you typed them, and only insignificant whitespace is dropped. Spaces inside strings are kept. Lines are joined with a newline, so there is no trailing blank line. Invalid JSON, a top-level object, a bare number or string, or a trailing comma gives no result. An empty array [] is valid: the output is empty and the count is 0. The result shows the element count and a validity note.

Worked example

Paste an array of two objects: [{"id": 1, "name": "Ada", "tags": ["x", "y"]}, {"id": 2, "name": "Bo"}]. The tool finds 2 elements, reports "Yes — valid JSON array" and prints two lines. Line 1 is {"id":1,"name":"Ada","tags":["x","y"]} and line 2 is {"id":2,"name":"Bo"}. The spaces after the colons and commas have been removed, and the nested tags array stays inside its object on a single line, so each line can be parsed by itself.

Try this example →

Common mistakes

  • Pasting a single object or a wrapper such as {"items":[...]}. Only a top-level array is accepted, so extract the array first.
  • Expecting the converter to tidy numbers. They are copied verbatim, so 1.0 stays 1.0 and 1e3 stays 1e3; a consumer that is strict about number formats will see exactly what you pasted.
  • Leaving a trailing comma or a comment in the array, as in [1,2,]. Strict JSON does not allow them, and the tool gives no result until you remove them.
  • Assuming duplicate keys are cleaned up. {"a":1,"a":2} is passed through unchanged with both keys, and what a downstream parser does with them depends on that parser.
  • Expecting a final newline at the end of the file. The output is lines joined by newlines with none after the last line, and some bulk APIs require one; add it yourself.

About this calculator

NDJSON (newline-delimited JSON, also called JSON Lines) rewrites a single JSON array of objects as one compact, self-contained JSON value per line, with no enclosing brackets or comma separators between entries. Because each line is independently parseable, a consumer can start processing before the whole file has arrived and can recover from a single malformed line without losing the rest of the stream — something a single giant JSON array cannot do.

This is why NDJSON is the format expected by streaming and log pipelines such as the Elasticsearch/OpenSearch bulk API, Fluentd and many big-data tools that read input record by record rather than loading an entire structure into memory. This converter takes a standard JSON array and emits it as NDJSON, one minified value per line, ready to pipe into those systems.

Was this helpful?

You can pick up to 3 reactions.

Comments

  • Be the first to comment.

Popular calculators

All Calculators