MiSawa / xq

Pure rust implementation of jq
MIT License
333 stars 18 forks source link

Implement input and Inputs #116

Closed MiSawa closed 2 years ago

itchyny commented 2 years ago

Note that the inputs filter is often used with -n to reduce all the input values.

❯ jq -n '., reduce inputs as $x (0; . + $x)' <<< '1 2 3 4 5'
null
15

❯ jq '., reduce inputs as $x (0; . + $x)' <<< '1 2 3 4 5' 
1
14

❯ xq -n '., reduce inputs as $x (0; . + $x)' <<< '1 2 3 4 5'
null
0

❯ xq '., reduce inputs as $x (0; . + $x)' <<< '1 2 3 4 5' 
1
14

❯ xq --version                                           
xq 0.2.21-111ca589af6ab3cf3f32bfa6c041a05f1eb0189f
MiSawa commented 2 years ago

Ah what...?? That looks really useful, but I don't understand the semantics of -n then..... :thinking:

wader commented 2 years ago

for https://github.com/wader/fq i implemented it by a global array of files to read, input reads/decodes on file, inputs repets input and then let the -n flag decide if if first input should be input or null. I guess for jq it's a bit more complicated as one file can have multiple JSON values or on value cab span multiple files as i understand it.

MiSawa commented 2 years ago

Thanks, yeah it doesn't seem to be the case for jq as you mentioned... though I think I figured out in #120.

wader commented 2 years ago

Nice! and also nice to see all the progress on xq