My json file 'veggies.json' as follows:
{"plants":
{"veggies":
[
{"section":"TUBERS",
"values":
[
{"tuber":"potato","type":"stem"}
]
},
{"section":"LEGUMES",
"values":
[
{"legume":"beans"},
{"legume":"peanuts"}
]
}
]
}
}
I want to add another tuber "yam", which is of type "root" - this has to go under the section TUBERS.
I've just started off with JSON, and I have been breaking my head with all sorts of jq commands, but to not much avail.
I tried to read the value at values[0] with the following command, but I don't seem to be able to list anything:
jq -r "[.[] | select(.plants.veggies.section == \"TUBERS\") | .plants.veggies.values.tuber]" veggies.json
Essentially, I am trying to achieve this - if plants section is TUBERS, add tuber "yam" which is of type "root"
Can anybody please help me out?
Oh, and I am stuck with jq version 1.2, if that matters (backward compatibility and all that stuff).
Much thanks in advance.