【发布时间】:2017-06-29 17:41:59
【问题描述】:
我是 JQ 的新手,我认为这应该可以得到我正在寻找的东西,但它会引发无法解决的错误。
cat aws_test_query_history_pipeline.json | jq '.parameters[] | map(if
.id == "clusterName"
then . + {"id"="changed"}
else .
end
)' >> test_krish.json
jq: error: syntax error, unexpected '=', expecting '}' (Unix shell
quoting issues?) at <top-level>, line 2:
then . + {"id"="changed"}
jq: 1 compile error
我知道我错过了一些愚蠢的东西,请告诉我我错过了什么。
更新这个问题,因为我错过了一些关于它的信息。
对此感到抱歉。这是我的示例
{
"objects": [
{
"connectionString": "jdbc:mysql:
1.rds.amazonaws.com",
"*password": "",
"name": "Insights",
"id": "DataNodeId_XAL9t",
"type": "MySqlDataNode",
"table": "stas",
"username": "porta"
},
{
"dependsOn": {
.......
]
"parameters": [
{
"id": "clusterName",
"description": "Which region Cluster name to use",
"type": "String",
"default": ""
},
{
"id": "password",
"description": "Password to use",
"type": "String",
"default": ""
}
]
}
以上是在 file.json 上运行此命令时,它只是让我更改了命令中提到的参数数组,但我还需要保持剩余的 json 文件不变
cat test.json | jq '.parameters | if .id == "clusterName" then .id =
"changed" elif .id == "password" then .id = "passchange" else . end' >
test_krish.json
上面的命令只是给我
{
"id": "changed",
"description": "Which region Cluster name to use",
"type": "String",
"default": ""
}
{
"id": "passchange",
"description": "Password to use",
"type": "String",
"default": ""
}
【问题讨论】: