且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用jq更新json文档中的单个值?

更新时间:2023-02-14 08:53:08

您可以使用=运算符设置对象的值.另一方面,|=用于更新值.这是一个微妙但重要的区别.过滤器的上下文发生变化.

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