Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract a field from each object in an array with jq?

Tags:

json

jq

I performed a cURL request to get all the users in our Gitlab server, like this.

$ curl -H "Private-Token: a;sldkfja;slkdfj" https://gitlab.domain.com/api/v3/users?active=true > my_file.json

and (part of) my_file.json looks like:

[
  {
    'username' : 'jdoe',
    'name' : 'John Doe',
    ...
  },
  {
    'username' : 'jadoe',
    'name' : 'Jane Doe',
    ...
  }
]

I stored the response in my_file.json. How can I use jq to get all the username values?

$ cat my_file.json | jq -r 'what to put here?'
like image 365
Chris F Avatar asked Jan 24 '18 15:01

Chris F


1 Answers

$ jq -r '.[].username' my_file.json jdoe jadoe 
like image 154
John Kugelman Avatar answered Sep 23 '22 08:09

John Kugelman