Another question re ‘jq’ formatting onto a single line. Here is my json file:
"facet_counts":{
"facet_queries":{},
"facet_fields":{
"title":[
"primary",5981,
"database",5965,
"source",5963,
"eecm",5949,
"the",5066,
"research",4888]},
"facet_ranges":{}
}
}
As you see there is no label assigned for the tuplets within the title array. I want to print the output like: –
"primary",5981,
"database",5965,
"source",5963,
"eecm",5949,
"the",5066,
"research",4888
So far, I’ve been trying jq -c ‘.facet_counts.facet_fields.title[]’, but members of the tuplet are being output on different lines (i.e. effectively decoupled): –
"primary"
5981
"database"
5965
"source"
5963
"eecm"
5949
"the"
5066
"research"
4888
2
Answers
You can split the array into chunks with
_nwise
, thenjoin()
those with a char of your liking:JqPlay Demo
Just pipe the output of
jq
to format it: