deno-ndjson
CLI tools for dealing with ndjson in Deno. Heavily inspired by ndjson-cli for node.
ndj-cat
reads a ndjson file into the console line by line
install
deno install --allow-read https://raw.githubusercontent.com/idris-maps/deno-ndjson/master/ndj-cat.tsusage
ndj-cat <PATH_TO_NDJSON_FILE>example
ndj-cat some_folder/file.ndjsonndj-map
maps every line of an ndjson.
Takes one argument, the expression to map.
The expression assumes there are two arguments:
d, thejsonlinei, the index of the line
install
deno install https://raw.githubusercontent.com/idris-maps/deno-ndjson/master/ndj-map.tsusage
ndj-map <EXPRESSION>example
Suppose you have a file.ndjson such as:
{"nom":"Lausanne","population":138905}
{"nom":"Yverdon-les-Bains","population":30143}
{"nom":"Montreux","population":26574}
{"nom":"Renens","population":21036}
{"nom":"Nyon","population":20533}
{"nom":"Vevey","population":19827}ndj-cat file.ndjson \
| ndj-map '({ index: i, town: d.nom })'will return
{"index":0,"town":"Lausanne"}
{"index":1,"town":"Yverdon-les-Bains"}
{"index":2,"town":"Montreux"}
{"index":3,"town":"Renens"}
{"index":4,"town":"Nyon"}
{"index":5,"town":"Vevey"}ndj-filter
filters lines of an ndjson.
Takes one argument, an expression that assumes two arguments:
d, thejsonlinei, the index of the line
install
deno install https://raw.githubusercontent.com/idris-maps/deno-ndjson/master/ndj-filter.tsusage
ndj-filter <EXPRESSION>example
Suppose you have a file.ndjson such as:
{"nom":"Lausanne","population":138905}
{"nom":"Yverdon-les-Bains","population":30143}
{"nom":"Montreux","population":26574}
{"nom":"Renens","population":21036}
{"nom":"Nyon","population":20533}
{"nom":"Vevey","population":19827}ndj-cat file.ndjson \
| ndj-filter 'd.population > 30000'will return
{"nom":"Lausanne","population":138905}
{"nom":"Yverdon-les-Bains","population":30143}ndj-reduce
reduces an ndjson.
Takes either no arguments or two arguments.
If there are no arguments, it will return a json array.
If there are arguments, there must be two: the expression and the initial value. The expression assumes three arguments:
a, the accumulatord, thejsonlinei, the index
install
deno install https://raw.githubusercontent.com/idris-maps/deno-ndjson/master/ndj-reduce.tsusage
ndj-reduce
## or
ndj-reduce <EXPRESSION> <INITIAL_VALUE>examples
Suppose you have a file.ndjson such as:
{"nom":"Lausanne","population":138905}
{"nom":"Yverdon-les-Bains","population":30143}
{"nom":"Montreux","population":26574}
{"nom":"Renens","population":21036}
{"nom":"Nyon","population":20533}
{"nom":"Vevey","population":19827}ndj-cat file.ndjson \
| ndj-reducewithout arguments, it will return
[{"nom":"Lausanne","population":138905},{"nom":"Yverdon-les-Bains","population":30143},{"nom":"Montreux","population":26574},{"nom":"Renens","population":21036},{"nom":"Nyon","population":20533}]ndj-cat file.ndjson \
| ndj-reduce 'a + d.population' 0with arguments, it will return
237191