小编spi*_*man的帖子

jq 错误语法错误,意外的“=”,期望“}”(Unix shell 引用问题?)在 <top-level>

cat test.json | jq 'map(if ParameterKey == "Project"           then . + {"ParameterValue" = "jess-project"}             else .             end           )'

jq: error: syntax error, unexpected '=', expecting '}' (Unix shell quoting issues?) at <top-level>, line 1:
map(if ParameterKey == "Project"           then . + {"ParameterValue" = "jess-project"}             else .             end           )                                                                      
jq: 1 compile error
Run Code Online (Sandbox Code Playgroud)

syntax-error jq

5
推荐指数
1
解决办法
1万
查看次数

jq不使用参数替换json值

test.sh不会替换test.json参数值($ input1和$ input2)。result.json具有相同的ParameterValue“ $ input1 / solution / $ input2.result”

 [
    {
      "ParameterKey": "Project",
      "ParameterValue": [ "$input1/solution/$input2.result" ]
     }
    ]
Run Code Online (Sandbox Code Playgroud)

test.sh

#!/bin/bash
input1="test1"
input2="test2"
echo $input1
echo $input2
cat test.json | jq 'map(if .ParameterKey == "Project"           then . + {"ParameterValue" : "$input1/solution/$input2.result" }             else .             end           )' > result.json
Run Code Online (Sandbox Code Playgroud)

variables json string-literals string-interpolation jq

4
推荐指数
1
解决办法
1511
查看次数