我正在使用JQ Play。
这是我的 JSON 数据 -
{
"body":{
"primarykey": [
"book_id",
"edition_id"
],
"members": [
{
"name": "book_id",
"type": "NUMBER"
},
{
"name": "edition_id",
"type": "NUMBER"
},
{
"name": "title",
"type": "VARCHAR2"
}
],
"links": [
{
"rel": "collection",
"href": "https://tdcvm28s16.bcone.com:7002/ords/testords/metadata-catalog/",
"mediaType": "application/json"
},
{
"rel": "canonical",
"href": "https://tdcvm28s16.bcone.com:7002/ords/testords/metadata-catalog/books/",
"mediaType": "application/json"
},
{
"rel": "alternate",
"href": "https://tdcvm28s16.bcone.com:7002/ords/testords/open-api-catalog/books/",
"mediaType": "application/openapi+json"
},
{
"rel": "describes",
"href": "https://tdcvm28s16.bcone.com:7002/ords/testords/books/"
}
]
}
}
我的JQ-
.body.primarykey[] | "{" + . + "},"
电流输出-
"{book_id},"
"{edition_id},"
我的预期输出是-
{"book_id"},
{"edition_id"}
这里如果有更多主键,它们也应该被附加到预期输出中。
请帮助我找到可以在 jqplay.org 中使用的正确 JQ
如果您可以接受尾随逗号:
jq -r '.body.primarykey[] | "{\"\(.)\"},"'
没有结尾的逗号:
jq -r '.body.primarykey | map("{\"\(.)\"}") | join(",\n")'