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

前端 未结 3 1889
离开以前
离开以前 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:36

    Update a value (sets .foo.bar to "new value"):

    jq '.foo.bar = "new value"' file.json
    

    Update a value using a variable (sets .foo.bar to "hello"):

    variable="hello"; jq --arg variable "$variable" '.foo.bar = $variable' file.json
    

提交回复
热议问题