Re:Jq – A Command-line JSON processor
by drdoom on Monday April 27, 2015 @02:51PM
(#9448383)
Looks interesting. Given this json,
[{"name":"john", "grades":[1,2,3]}, {"name":"jane", "grades":[4,5,6]}],
can it print it out as this:
john,1
john,2
john,3
jane,4
jane,5
jane,6
[ Parent
| on HN ]
Yes, kind of like so:
echo '[{"name":"john", "grades":[1,2,3]}, {"name":"jane", "grades":[4,5,6]}]'| jq '.[]| "\(.name), \(.grades|.[])"'
Thanks! Now, it looks more interesting...
Based on @aquassaut's answer, I tweaked it a little, and this should do it.
echo '[{"name":"john", "grades":[1,2,3]}, {"name":"jane", "grades":[4,5,6]}]' | jq -r '.[] | "\(.name),\(.grades|.[])"' | paste -sd' ' -