Given following json content ,
{
"application": "grafana",
"users": {
"admin": {
"display-name": "admin",
"access": "admin"
},
"user1": {
"display-name": "user1",
"access": "read"
},
"user2": {
"display-name": "user2",
"access": "edit"
}
}
}
I want to produce tsv format like following :
Application User Access
grafana admin admin
user1 read
user2 edit
How can I use jq @tsv to achieve that ?
is there a way to only display application name in first row ?
One could utilize the facts that transpose
compensates for a rigged matrix using null
values, and that @tsv
gracefully translates null
values to empty strings:
[["Application"], ["User"], ["Access"]],
[[[.application]], [.users[] | [."display-name", .access]]]
| transpose[] | flatten(1) | @tsv
The same without butchering the headers array:
["Application", "User", "Access"], (
[[[.application]], [.users[]|[."display-name",.access]]]
| transpose[] | flatten(1)
) | @tsv
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