I am trying to export a very large JSON file (zip compressed: full_ip-port.json) to CSV.
The file consists of a single JSON object that has a regular structure. Here is a representative extract (obtained by [to_entries[0,1]] | from_entries
):
{
"1122595": [
{
"ioc_value": "103.100.159.212:443",
"ioc_type": "ip:port",
"threat_type": "botnet_cc",
"malware": "win.cobalt_strike",
"malware_alias": "Agentemis,BEACON,CobaltStrike,cobeacon",
"malware_printable": "Cobalt Strike",
"first_seen_utc": "2023-05-27 02:31:39",
"last_seen_utc": null,
"confidence_level": 100,
"reference": null,
"tags": "CLOUDIE-AS-AP Cloudie Limited,CobaltStrike,cs-watermark-666666",
"anonymous": "0",
"reporter": "drb_ra"
}
],
"1122593": [
{
"ioc_value": "167.172.72.193:23",
"ioc_type": "ip:port",
"threat_type": "botnet_cc",
"malware": "elf.bashlite",
"malware_alias": "gayfgt,Gafgyt,qbot,torlus,lizkebab",
"malware_printable": "Bashlite",
"first_seen_utc": "2023-05-27 01:40:04",
"last_seen_utc": null,
"confidence_level": 75,
"reference": "https://bazaar.abuse.ch/sample/6c901ba15327da68159712a9726807fb08868309726c55ef202818bfde22a5a7/",
"tags": "Gafgyt",
"anonymous": "0",
"reporter": "abuse_ch"
}
]
}
What I have so far:
Inner Part:
jq -r '.[] | .[] | to_entries | map(.value) | @csv' full_ip-port.json
Missing ID:
jq -r '{id: (. | keys[])} | to_entries | map(.value) | @csv' full_ip-port.json
How can I bring it together to a nice and clean CSV file?