I've a large JSON file where I'd like to transform some values based on some kind of mapping.
The data I have looks like:
[ {"id":1, "value":"yes"}, {"id":2, "value":"no"}, {"id":3, "value":"maybe"}]
And I'd like to transform that into a list like this:
[ {"id":1, "value":"10"}, {"id":2, "value":"0"}, {"id":3, "value":"5"}]
With the fixed mapping:
yes => 10no => 0maybe => 5
My current solution is based on a simple if-elif-else
combination like this:
cat data.json| jq '.data[] | .value = (if .value == "yes" then "10" elif .value == "maybe" then "5" else "0" end)'
But this is really ugly and I'd love to have a more direct way to express the mapping.
Thanks for your help