Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 527

Nested Json invocation

$
0
0

I have a jq script like this:

jq -s 'add' \< ./tmp/dispatch_03494ecb-9f72-3233-b4dc-173aa725dc24.json \< ./tmp/dispatch_03494ecb-9f72-3233-b4dc-173aa725dc24_acknowledgement.json | \    jq '{         success: .result == "ok",         event_type,         start_time,         end_time     }'

and I have a file: $SUCCESS_FILE containing a bunch of base json files, ie:

./tmp/dispatch_03494ecb-9f72-3233-b4dc-173aa725dc24.json

Which I can tranform to get an array of the path to both the base file and the ack file, ie use this:

jq -Rn '    [inputs] |    map({        base_file: .,        ack_file: (.[:-5] +"_acknowledgement.json")    })'< "$SUCCESS_FILE" | jq '.'

to get

[  {"base_file": "tmp/dispatch_03494ecb-9f72-3233-b4dc-173aa725dc24.json""ack_file": "tmp/dispatch_03494ecb-9f72-3233-b4dc-173aa725dc24_acknowledgement.json"  },]

I want to combine the two scripts so that for each element of the said array I do a jq invocation with the values of the keys: {base_file, ack_file}

ie, in FP lingo, I want to flatmap the jq invocation demonstrated earlier to the elements of the array as constructed by the latter jq invocation. Have no idea how though.

If this is not possible via jq alone, how can I do this in the shell layer? ideally in zsh


Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>