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

how to alter values in a field of a json array with jq?

$
0
0

I would like to assign different values to a same field in a json array using jq command line utility,

for example let's take this:

myjson='[{"a":1,"b":"john"}, {"a":2, "b":"mark"}]'

with the following I can assign all fields a same value

echo $myjson | jq '[.[] | .a=5 ]'

I can also increment it:

echo $myjson | jq '[.[] | .a+=2]'

but how can I assign two new different values like 7 and 3 to the two a fields in the objects in the array?

using the following, or similar assigns a whole array to each variable

echo $myjson | jq '[.[] | .a=[7,3]]'

Viewing all articles
Browse latest Browse all 657

Trending Articles



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