我想用一个新值替换 "id" 的值。 我有以下 json 文件。
[
{
"adminConsentDescription": "default",
"adminConsentDisplayName": "default",
"id": "5ad89ced-56a1-2222-8200-1ded5129d788",
"isEnabled": true,
"type": "User",
"userConsentDescription": null,
"userConsentDisplayName": null,
"value": "default"
}
]
并想用变量app_id替换它
app_id=6e663913-0000-3456-c083e40fbc99
输出应该是
[
{
"adminConsentDescription": "default",
"adminConsentDisplayName": "default",
"id": "6e663913-0000-3456-c083e40fbc99",
"isEnabled": true,
"type": "User",
"userConsentDescription": null,
"userConsentDisplayName": null,
"value": "default"
}
]
我尝试并达到了能够使用 Jq 提取价值的地步
先定义变量
App_id=6e663913-0000-3456-c083e40fbc99
jq --argjson id $app_id 'map(."id" = $app_id)' oauth2-permissions.json
尝试了几个其他排列,但无法用变量替换。有什么想法吗?
您可以使用:
APP_ID=6e663913-0000-3456-c083e40fbc99
jq --arg app_id "$APP_ID" '.[].id = $app_id' oauth2-permissions.json