Update one JSON file values with values from another JSON using JQ

后端 未结 2 424
梦毁少年i
梦毁少年i 2021-01-23 18:45

So I have two JSON files:

bosh.json:

{
  \"key_pair_name\": \"my-aws-keypair\",
  \"ssh_private_key\": \"my-key-name\",
  \"trusted_certific         


        
2条回答
  •  独厮守ぢ
    2021-01-23 19:39

    jq solution:

    jq --argfile bosh bosh.json 'with_entries( 
             if $bosh[.key] then .value = $bosh[.key] else . end)' model.json
    

    The output:

    {
      "trusted_certificates": "my-trusted-certs",
      "vm_password_type": "generate"
    }
    

    • if $bosh[.key] then .value = $bosh[.key] else . end - update model's value only for matched keys

提交回复
热议问题