How do I select multiple fields in jq?

jq
J. Groesser picture J. Groesser · Jan 17, 2016 · Viewed 87.5k times · Source

My input file looks something like this:

{
"login": "dmaxfield",
"id": 7449977,
...
}
{
"login": "dmaxfield",
"id": 7449977,
...
}

I can get all the login names with this : cat members | jq '.[].login'

but I have not been able to crack the syntax to get both the login and id?

Answer

user3899165 picture user3899165 · Jan 17, 2016

You can use jq '.[] | .login, .id' to obtain each login followed by its id.