Manipulate JSON with jq

后端 未结 2 1098
既然无缘
既然无缘 2021-01-28 05:37

I have following the json file. I am trying to update a couple of properties in this file using jq

{
  \"href\" : \"http://localhost:8080/api/v1/clu         


        
2条回答
  •  执笔经年
    2021-01-28 06:32

    The original question asks how to alter more than one of the "properties". The key to doing so without being repetitive is |=. Here's an illustration:

    .items[0].properties |=
      ( .["hfile.block.cache.size"] = "newvalue1"
      | .["hbase.hregion.max.filesize"] = "newvalue2" )
    

    In-place updates

    The original question also mentioned updating properties within a file. One possibility that avoids having to create an explicit temporary file is to use sponge (e.g. brew install moreutils), along the lines of:

    $ jq .... input.json | sponge input.json 
    

提交回复
热议问题