input json:
[
{
"login": "u1",
"name": "u1",
"role": "User",
"groups": [
{
"id": "1234",
"name": "G1"
},
{
"id": "1235",
"name": "G2"
}
],
"created": "2020-05-11 11:06"
},
{
"login": "u2",
"name": "u2",
"role": "User",
"groups": null,
"created": "2020-05-11 11:06"
}
]
I use following filter to get users and groups they are member of:
$ jq -r '
.[]
| [.login,
.name,
( if .groups == null
then "grp:-"
else (del(.groups[]
| select(.name=="All Users"))
| [.groups[].name] | join("|"))
end )]
| @tsv' json
u1 u1 G1|G2
u2 u2 grp:-
How to add grp: prefix for each found group?
Expected output would be:
u1 u1 grp:G1|grp:G2
u2 u2 grp:-