json jq -从外部数组添加元素

epggiuax  于 2023-03-13  发布在  其他
关注(0)|答案(1)|浏览(96)
{
    "TypeName": "AWS:Application",
    "InstanceId": "i-0af68a7cf857bd010",
    "SchemaVersion": "1.1",
    "CaptureTime": "2023-03-01T16:28:43Z",
    "Entries": [
        {
            "ApplicationType": "admin",
            "Architecture": "x86_64",
            "Name": "accountsservice",
            "PackageId": "accountsservice_0.6.45-1ubuntu1.3_amd64.deb",
            "Publisher": "Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>",
            "Summary": "query and manipulate user account information",
            "URL": "https://www.freedesktop.org/wiki/Software/AccountsService/",
            "Version": "0.6.45-1ubuntu1.3"
        }
     ]
}

这是一个片段的一个大的选择,我试图格式化,最终导出为csv。
x一个一个一个一个x一个一个二个x
是否有一种方法可以将.InstanceId从数组外部插入到数组中,从而使我得到:

[
  "i-0af68a7cf857bd010",
  "admin",
  "accountsservice",
  "0.6.45-1ubuntu1.3",
  "accountsservice_0.6.45-1ubuntu1.3_amd64.deb",
  "Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>",
  "https://www.freedesktop.org/wiki/Software/AccountsService/",
  "query and manipulate user account information"
]

Thank you so much for the assistance!
l7mqbcuq

l7mqbcuq1#

你可以连接两个流的数组(一个流包含一个数组,另一个流包含多个数组),这样就建立了两个流的笛卡尔积。

[.InstanceId] + (.Entries[] | [.ApplicationType, .Name, .Version, .PackageId, .Publisher, .URL, .Summary])

输出:

[
  "i-0af68a7cf857bd010",
  "admin",
  "accountsservice",
  "0.6.45-1ubuntu1.3",
  "accountsservice_0.6.45-1ubuntu1.3_amd64.deb",
  "Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>",
  "https://www.freedesktop.org/wiki/Software/AccountsService/",
  "query and manipulate user account information"
]

相关问题