【发布时间】:2021-08-30 23:36:30
【问题描述】:
我在像这样调用 jq 时看到 is not defined at <top-level>:
jq ".Changes[0].ResourceRecordSet.Name = word-is-here.domain.com" someFile.json
对于替换的第二侧中由破折号分隔的每个单词,该错误都会重复。完整的错误就像
jq: error: word/0 is not defined at <top-level>, line 1:
.Changes[0].ResourceRecordSet.Name = word-is-here.domain.com
我尝试过以多种不同的方式转义引号,但这并没有帮助。 (我的意思是在做“'”''奇怪的事情,我还在学习 bash,所以我只是在墙上乱扔东西直到它粘住)
编辑:
所以我试图在 bash 脚本中运行它,= 符号的两侧都是变量,例如 jq --arg value "$value" --arg key "$key" '$key = $value' "$path"(我在建议后尝试过)
并得到错误: 路径表达式无效,结果为“.Changes[0].ResourceRecor...
我使用的json是这样的:
{
"Changes": [
{
"Action": "do something",
"ResourceRecordSet": {
"Name": "some name here to replace",
...
}
}
]
}
【问题讨论】:
-
您能否提供一部分 json 以便我们重现该问题?
-
今后,请尽可能遵循minimal reproducible example 准则。谢谢。
-
@AntonioPetricca 我已经用 json 的一部分更新了这个问题,并详细说明了我在尝试不同的东西(即使用 args)时遇到的其他错误