#json-parser #ndjson #order

bin+lib unnest-ndjson

Convert large JSON documents to ndjson/jsonlines

2 releases

0.1.1 Oct 7, 2022
0.1.0 Sep 19, 2022

#894 in Encoding


447 lines


This tool can unpack JSON objects into ndjson, also called jsonlines.

ndjson is much easier to consume than JSON objects in some situations.


  • TARGET_DEPTH: how many levels of document to strip away
  • --path: include the path to the element, as the key


Say you have a JSON document that looks like:

  {"name": "john", "class": "warrior"},
  {"name": "sam", "class": "wizard"},
  {"name": "alex", "class": "terrible"}

You could produce:

<array.json unnest-ndjson 1

That is, removing the outer array wrapper.

Or, with --path, it can produce:


Or, with --path 2, it can produce:


A similar thing works for non-array documents, like:

  "john": {"class": "warrior"},
  "sam": {"class": "wizard"},
  "alex": {"class": "terrible"}

You might want:



It's quite fast, and uses very little memory. This could be useful if you wanted to process the resulting, much smaller, JSON documents with another application.

On 2019 hardware, it can process JSON at about 1GB/s, and needs approximately no memory to do so.

A 300MB file can be converted in 300ms and 3MB of RAM, regardless of settings. For comparison, jq takes over 2 seconds, and 350MB of RAM, to read the same file, even if it is not printing any of it.


It's a custom JSON "parser" (scanner? bracket matcher?), which doesn't try and actually load the JSON into memory, or decode any of the idiosyncrasies.


MIT OR Apache-2.0