我执行了一个 cURL 请求来获取我们 Gitlab 服务器中的所有用户,就像这样。
$ curl -H "Private-Token: a;sldkfja;slkdfj" https://gitlab.domain.com/api/v3/users?active=true > my_file.json
和(部分)my_file.json 看起来像:
[
{
'username' : 'jdoe',
'name' : 'John Doe',
...
},
{
'username' : 'jadoe',
'name' : 'Jane Doe',
...
}
]
我将响应存储在
my_file.json
中.我如何使用 jq
获取所有 username
值(value)观?$ cat my_file.json | jq -r 'what to put here?'
最佳答案
$ jq -r '.[].username' my_file.json
jdoe
jadoe
关于json - 如何使用jq从数组中的每个对象中提取字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48426052/