使用 jq 使用此字符串构建另一个 json 对象
Using jq to build another json object with this string
目前我正在使用 packer 将 AWS AMI 复制到多个区域,然后使用 Packer 的 post 处理器输出 AMI ID:https://packer.io/docs/post-processors/manifest.html.
这是输出示例:
{
"name": "amazon-ebs",
"builder_type": "amazon-ebs",
"build_time": 1584037532,
"files": null,
"artifact_id": "ca-central-1:ami-02420*,us-east-1:ami-06a4*,us-west-1:ami-078cf*",
"packer_run_uuid": "",
"custom_data": null
}
我想使用 jq 以这种格式构建新的 json:
{
"ca-central": "ami_id",
"us-east-1": "ami_id",
"us-west-1": "ami_id"
}
有人能帮我用 jq 命令吗?
根据您的输入,以下 jq 程序:
.artifact_id
| [ split(",")[]
| (split(":") | {(.[0]): .[1] } ) ]
| add
产生:
{
"ca-central-1": "ami-02420*",
"us-east-1": "ami-06a4*",
"us-west-1": "ami-078cf*"
}
目前我正在使用 packer 将 AWS AMI 复制到多个区域,然后使用 Packer 的 post 处理器输出 AMI ID:https://packer.io/docs/post-processors/manifest.html.
这是输出示例:
{
"name": "amazon-ebs",
"builder_type": "amazon-ebs",
"build_time": 1584037532,
"files": null,
"artifact_id": "ca-central-1:ami-02420*,us-east-1:ami-06a4*,us-west-1:ami-078cf*",
"packer_run_uuid": "",
"custom_data": null
}
我想使用 jq 以这种格式构建新的 json:
{
"ca-central": "ami_id",
"us-east-1": "ami_id",
"us-west-1": "ami_id"
}
有人能帮我用 jq 命令吗?
根据您的输入,以下 jq 程序:
.artifact_id
| [ split(",")[]
| (split(":") | {(.[0]): .[1] } ) ]
| add
产生:
{
"ca-central-1": "ami-02420*",
"us-east-1": "ami-06a4*",
"us-west-1": "ami-078cf*"
}