如何使用jq将多个json对象转换为一个对象?

问题描述:

输入:如何使用jq将多个json对象转换为一个对象?

{ 
    "ip": { 
    "ip_ip_dst": "4.2.2.2", 
    "ip_ip_src": "192.168.2.208" 
    }, 
    "dns": { 
    "text_dns_qry_class": "0x00000001", 
    "text_dns_a": "104.199.136.182", 
    "text_dns_qry_name_len": "15", 
    "text_dns_qry_name": "vehere.odoo.com", 
    "text_dns_resp_type": "1", 
    "text_dns_qry_type": "1" 
    }, 
    "frame": { 
    "frame_frame_len": "79", 
    "frame_frame_time": "Aug 9, 2017 13:21:29.987979869 IST" 
    } 
} 

输出应该是:

{ 
    "ip_ip_dst": "4.2.2.2", 
    "ip_ip_src": "192.168.2.208" 
    "text_dns_qry_class": "0x00000001", 
    "text_dns_a": "104.199.136.182", 
    "text_dns_qry_name_len": "15", 
    "text_dns_qry_name": "vehere.odoo.com", 
    "text_dns_resp_type": "1", 
    "text_dns_qry_type": "1" 
    "frame_frame_len": "79", 
    "frame_frame_time": "Aug 9, 2017 13:21:29.987979869 IST" 

} 

您正在寻找add功能:

jq 'add' file.json 

[.[]] | add 

应该做的伎俩。