How do I update a single value in a json document using jq?

前端 未结 3 1893
离开以前
离开以前 2020-12-01 06:11

Appologies if I\'ve overlooked something very obvious; I\'ve just found jq and am trying to use it to update one JSON value without affecting the surrounding da

3条回答
  •  天命终不由人
    2020-12-01 06:16

    You set values of an object using the = operator. |= on the other hand is used to update a value. It's a subtle but important difference. The context of the filters changes.

    Since you are setting a property to a constant value, use the = operator.

    .shipping.local = false
    

    Just note that when setting a value to a property, it doesn't necessarily have to exist. You can add new values easily this way.

    .shipping.local = false | .shipping.canada = false | .shipping.mexico = true
    

提交回复
热议问题