我需要从 JSON 文件中提取特定的防病毒产品扫描结果,并以 csv 格式列出元素以供进一步处理。JSON 文件示例如下:
Contents of a file scanresults.json
{"scans": {"Bkav": {"detected": true, "version": "1.3.0.9899", "result": "W32.AIDetect.malware2", "update": "20230417"}, "Lionic": {"detected": true, "version": "7.5", "result": "Trojan.Win32.Generic.4!c", "update": "20230417"}, "Elastic": {"detected": true, "version": "4.0.85", "result": "malicious (high confidence)", "update": "20230413"}, "MicroWorld-eScan": {"detected": true, "version": "14.0.409.0", "result": "Trojan.Ransom.Cerber.1", "update": "20230417"}}}
JSON 按产品组织防病毒扫描结果。需要以 csv 格式检索与产品“Elastic”相关的结果,以便进一步处理,如下所示:
detected, version, result, update
true, "4.0.85", "malicious (high confidence)", "20230413"
根据我的研究,可以通过 jq 命令提取结果,如下所示:
jq-win64.exe ".scans.Elastic" scanresults.json
{
"detected": true,
"version": "4.0.85",
"result": "malicious (high confidence)",
"update": "20230413"
}
尝试使用 map 函数提取 csv 格式的所需结果,但失败了。使用的参考链接是https://earthly.dev/blog/convert-to-from-json/。
谢谢提供解决方案和评论。