Use +
to concatenate strings:
jq -r '.[]
| [.login,.name,(
if .groups == null
then "grp:-"
else (
del(.groups[] | select(.name=="All Users"))
| ["grp:" + .groups[].name]
# ~~~~~~~~
| join("|")
)
end
)]
| @tsv'
You can even avoid specifying "grp:" twice, but you need to return an array from the then branch, too:
jq -r '.[]
| [.login, .name, (
(
if .groups == null
then ["-"]
else (
del(.groups[] | select(.name=="All Users"))
| [.groups[].name]
)
end
)
| map("grp:" + .)
| join("|")
)]
| @tsv'
Update:
Getting inspiration from peak I guess this produces the output you wanted:
jq -r '.[]
| .groups //= []
| del(.groups[] | select(.name=="All Users"))
| .groups[0] //= {name: "-"}
| [.login, .name, ( ["grp:" + (.groups[].name)] | join("|") ) ]
| @tsv'
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…