首页 > 解决方案 > 我可以使用什么 curl 命令将 JSON 上的值更改为 true

问题描述

{
    "properties": {
    "test": {
        "value": false,
        "name": "abc"
    }
}
}

我正在尝试使用 curl 命令,但该值未更改为 true

curl -u admin:password http://<host>/check.json | jq 'map(.properties.test.value = "true")' | curl -X PUT http://<host>/check.json

标签: jsoncurl

解决方案


您不能以这种方式通过管道将第二个命令的结果传递给第三个命令。

您需要将 JSON via-d作为正文传递给第二个请求。

UPDATED=$(curl -u admin:password http://<host>/check.json | jq 'map(.properties.test.value = "true")')
curl -X PUT -d "$UPDATED" http://<host>/check.json

推荐阅读