I am new to JQ, I have below json file
[
{
"userId" : "jens",
"firstName" : "jens",
"lastName" : "jens",
"emailAddress" : "[email protected]",
"source" : "default",
"status" : "active",
"readOnly" : false,
"roles" : [ "reader" ],
"externalRoles" : [ ]
}, {
"userId" : "admin",
"firstName" : "Administrator",
"lastName" : "User",
"emailAddress" : "[email protected]",
"source" : "default",
"status" : "changepassword",
"readOnly" : false,
"roles" : [ "app-admin" ],
"externalRoles" : [ ]
}]
Now I want to print as below format
"userId" : "jens","roles" : [ "reader" ]
"userId" : "admin", "roles" : [ "app-admin" ],
How can I achieve this? I tried with this command
jq -r '.[].userId,.[].roles'
but it scatters the data like below
jens
admin
[]
[
"reader",
"app-admins",
]
Please guide me how can I have above output.
\nexpanded to literal newlines etc.)? Usually, for queries like these, the task is to create CSV or tab-delimited output, which would be a saner and more straightforward request.