将 shell 变量中的 json 字符串转换为字符串文字

Converting json string in a shell variable to string literal

我有一个 shell 变量,其中包含 json 如下

{ "test" :"test", "temp":"temp" }

这是我从 jq 解析时得到的 json 的一部分,当我将其作为 [=34 的一部分传递给 curl 时,它是一个 json 解析器 tool.But =] 请求正文,它正在转换为

   '{' 
     '"test"' ':' 'test,'
      '"temp"' ':' 'temp'
   '}'

但我想要它

   '{
      "test" : "test",
      "temp" : "temp"
    }'

VAL=$(echo "$RET" | jq ".pending[$j].value")

VAL 是将包含 json 的变量 我需要将此 VAL 作为请求正文传递给 curl

curl -X POST -H "$CONTENT_HEADER" -H "$AUTH_HEADER" http://localhost:8080/testApi -d $VAL

shell 将其解释为多个参数。引用扩展(如 -d "$VAL")或将其通过管道传输而不是将其保存到变量 jq '...' | curl ...