I have the following input file:
{
"dic": {
"a": "",
"b": "",
"c": "",
"d": ""
},
"remove": {
"b": true,
"c": false,
"d": true
}
}
I want to remove with jq all elements of the dictionary dic
which are also in the dictionary remove
with the value true.
This would be the output:
{
"dic": {
"a": "",
"c": ""
},
"remove": {
"b": true,
"c": false,
"d": true
}
}
I am not sure how to do this. I would first need to clean the remove
dic and only get the keys with the value true. Then I would need to somehow only delete these keys from dic
.
You don't need anything other than JQ for that.
[.remove | path(.[] | select(.))] as $p | .dic |= delpaths($p)
Online demo
If there might be other values in remove
than true and false, use
select(. == true)
instead of
select(.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With