简体   繁体   中英

JQ combine json with key:value

I have two Json files

First:

''' { "KeyID": 7532173, "KeyDetails": "Level 12" } '''

Second: ''' { "KeyID": 7532173, "Level": "Access Level" } '''

I would like to combine them matching the key:value pair of KeyId

Please advise on how to proceed

You could use if... then... else... end , or more briefly, select :

jq -s 'select(.[0].KeyID==.[1].KeyID) | add' file1.json file2.json

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM