I am doing something fundamentally wrong but just can't see what, could some kind person point out my fault with jq or JSON here?
I have the the following child objects contained within an array “entries
”
{
"profile": {
"name": "TesterRun1",
"download": {
"entries": [{
"ENTRY_A": "testserver1_place_com",
"store": "A",
"type": "direct"
},
{
"ENTRY_B": "testserver2_anotherplace_com",
"store": "B",
"type": "bypass"
},
{
"ENTRY_B": "testserver2_anotherplace_com",
"store": "A",
"type": "bypass"
}
]
}
}
}
I wish to convert these to an array accessible by bash via the jq function “to_entries
” using the below query but so far nothing!
jq 'to_entries|.[]|.profile.download.entries|select(.store=="A")|.[]'
You can see here that nothing is returned on JQ Play - enter link description here
Please help save my sanity, what am I doing wrong
Here is a slightly different approach (with some cleaned-up data) which captures the output from
jq
into separate column arrays.Output
to_entries
has nothing whatsoever to do with exposing JQ results to bash. Rather, it takes each entry in a JSON object and emits a{"key": key, "value": value}
pair.That can be useful, if you want to identify and extract arbitrary keys. For example:
...will, when given your input on stdin, emit (albeit on a single line, without the whitespace changes):
...which I assume, for lack of any better description in the question, is what you actually want.