I have a file
[{
key: 'value',
key1:{
key:'value'
},
fields:[{
to:{
id:'value'
},
field:{
id:'value',
name:'value'
}
},
{key:'value'}]
}]
I need to find elements of initial array which have and array .fields[] which have .field.id==’status’ and .to.id==”closed”
I ve tried [.changelog[] | select(.fields[]|select(.field.id=="status" and (.to.key=="closed" or .to.key=="done")))]
A mistake ‘cannot iterate over null’ apears. Apparently, i can use .changelog[].fields
but i cant use .changelog[].fields[]
4
… .fields[] which have .field.id==’status’ and .to.id==”closed”
Assuming the sample data is translated to JSON (*), the following query, which corresponds to these requirements, would work:
select(.[].fields[] | select(.field and .field.id=="status" and (.to.id == "closed")))
This is just one of several reasonable possibilities, but the key point is that since not all items in .fields[] have a key named “field”, you cannot write a query that assumes they do.
(*) hjson will do the job.