从 json 文件中提取 属性 slug

Extract a property slug from a json file

在使用 API 通过 shell 脚本获取 bitbucket 中所有存储库的列表后,我想提取存储库的名称及其大小。我为此使用的命令是

repo_list=$(cat repo.json | jq '.[] | .slug ' | sed 's/"//g')

repo.json 包含:

{
"pagelen":100,
"size":494,
"values":[
  {
     "scm":"git",
     "website":"",
     "fork_policy":"no_public_forks",
     "full_name":"org_name/ecomm-dist-cache",
     "name":"ecomm-dist-cache",
     "language":"java",
     "created_on":"2014-11-18T19:01:25.741787+00:00",
     "mainbranch":{
        "type":"branch",
        "name":"master"
     },
     "workspace":{
        "slug":"org_name",
        "type":"workspace",
        "name":"Org Name ",
        "uuid":"{xxxxxxxxxxxxx}"
     },
     "has_issues":true,
     "updated_on":"2018-06-06T22:17:02.947496+00:00",
     "size":105095621,
     "type":"repository",
     "slug":"ecomm-dist-cache",
     "is_private":true,
     "description":"Initial Migration of ecomm-dist-cache"
  },
  {
     "scm":"git",
     "website":"",
     "full_name":"org_name/mqfte_ecommoutboundtransfertoweddingchannel",
     "name":"MQFTE_ECOMMOutboundTransferToWeddingChannel",
     "language":"",
     "mainbranch":{
        "type":"branch",
        "name":"master"
     },
     "workspace":{
        "slug":"org_name",
        "type":"workspace",
        "name":"Org Name ",
        "uuid":"{xxxxxxxxxxxxx}"
     },
     "has_issues":false,
     "size":99549,
     "type":"repository",
     "slug":"mqfte_ecommoutboundtransfertoweddingchannel",
     "is_private":true,
     "description":""
  }
],
"page":1,
"next":"https://api.bitbucket.org/2.0/repositories/org_name? pagelen=100&page=2"
}

我收到的错误信息是

Cannot index number with string "slug"

预期结果是

ecomm-dist-cache
mqfte_ecommoutboundtransfertoweddingchannel
jq -r '.values[].slug' repo.json

-r 将删除引号,因此无需通过管道传递给 sed。