首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从github动作中的curl响应中获取json字段值

从github动作中的curl响应中获取json字段值
EN

Stack Overflow用户
提问于 2022-03-05 03:50:23
回答 1查看 445关注 0票数 1

我有下面的curl请求,并附上响应的响应,我需要提取"status.azure.resource_name“的值,我是GitHub操作的新手,因此从8小时以上一直坚持这个问题,如果它是我现在已经解决的一些编程语言,请帮助它。

卷曲请求:

代码语言:javascript
复制
curl --location --request PUT $URL \
                                          --header "$AUTH_HEADER" \
                                          --header 'Content-Type: application/json' \
                                          --data-raw "$PAYLOAD)"

以及答复:

代码语言:javascript
复制
{
  "labels": {},
  "spec": {
    "mysql": {
      "version": "8.0",
      "sku": {
        "name": "GP_Gen5_4"
      },
      "storage_profile": {
        "storage_mb": 5120
      }
    },
    "key_vault": {
      "access_policies": [
        {
          "name": "test",
          "type": "group",
          "project": null
        }
      ]
    }
  },
  "type": "azure-mysql",
  "name": "mysql",
  "id": "1234",
  "created_at": "2012-03-04T10:00:05+00:00",
  "updated_at": "2012-03-04T10:00:05+00:00",
  "project": {
    "id": "ae3dfa99",
    "name": "Test",
    "url": "www.google.com",
    "geography": "in"
  },
  "links": {
    "key_vault": {
      "endpoint": {
        "url": "",
        "description": "test.",
        "display_name": "test"
      },
      "azure_portal": {
        "url": "test",
        "description": "Link to the resource in the Azure portal.",
        "display_name": "Key Vault Azure Portal"
      }
    },
    "azure_portal": {
      "url": "test",
      "description": "Link to the resource in the Azure portal.",
      "display_name": "Azure Portal"
    },
    "endpoint": {
      "url": "test",
      "description": "Azure resource endpoint.",
      "display_name": "test"
    }
  },
  "url": "test",
  "tags": {
    "cost_center_id": "471000",
    "customer": "internal",
    "product_group": "internal",
    "environment_type": "test",
    "budget_category": "",
    "team": ""
  },
  "spiffe_id": "test",
  "status": {
    "ready": false,
    "state": "reconciling",
    "deployment": {
      "steps": {}
    },
    "azure": {
      "resource_name": "test",
      "id": null,
      "subscription_id": "test",
      "resource_group": "test"
    },
    "key_vault": {
      "access_policies": []
    }
  }
}
EN

回答 1

Stack Overflow用户

发布于 2022-03-05 17:30:51

您只需使用jq来执行json解析。它已经可以使用在github动作跑步者中了。

在您的例子中,应该是这样的(我将您的响应json粘贴到test.json文件中)

代码语言:javascript
复制
$ cat test.json | jq .status.azure.resource_name
"test"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71359333

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档