Link Search Menu Expand Document

Arrays

add new element to existing array

link: https://stackoverflow.com/questions/42245288/add-new-element-to-existing-json-array-with-jq

jq '.data.messages[3] |= . + {"date": "2010-01-07T19:55:99.999Z", "xml": "xml_samplesheet_2017_01_07_run_09.xml", "status": "OKKK", "message": "metadata loaded into iRODS successfullyyyyy"}' inputJson

get output as a json array

jq '[.[] | {message: .commit.message, name: .commit.committer.name}]'

Rest

Get specific field from all elements of array

cat /tmp/out.json | jq '.[].cui'

"C0242402"
"C0026549"
"C0663448"
"C0018799"
"C2346927"
"C0553262"
"C3541968"

Get Keys

cat {json} jq “keys”

Query

< nyt.json jq -c '.results[] | {name, party, cash: .cash_on_hand} | select(.cash | tonumber > 1000000)'

Special char in key

cat public/docs/typescript/db.json| jq '.["handbook/basic-types"]'

jq -r

selecto multiple fields

jq ".s3Detail[] | .user,.SizeMb"

select with sort

cat data/2019-09-19-23.json | jq ".s3Detail.entries | sort_by(.Size)[]|.user,.SizeMb"


Copyright © 2020 Thence LLC