Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

How to update value in json object with key as argument (using `jq`)

$
0
0

Using jq I want to update a value in a json object.The key of the value to be updated is passed as an argument.

Input

{"a": 1,"b": 2,"c": 3}

Expected output with argument: key=b

{"a": 1,"b": 42,"c": 3}

I tried to do:

jq --arg key b '.($key) |= . + 40'jq --arg key b '".\($key)" |= . + 40'

Both attempts result in errors:

  • syntax error, unexpected '('
  • Invalid path expression with result ".b"

How can I solve this problem?


Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>