首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在github动作中解析curl的json响应

在github动作中解析curl的json响应
EN

Stack Overflow用户
提问于 2022-03-04 10:42:02
回答 1查看 1K关注 0票数 1

我有如下所示的curl请求,并附加了来自响应的curl请求的响应--如何获取"status.azure.resource_name“下的值,并将其存储在某个变量中,因为我是GitHub操作的新手,如果这是一些编程api,我可以解决它

请求:

代码语言: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-04 11:23:06

实现这一目标有多种方法。

  1. 您可以在bash步骤.

中直接使用jq和读取变量。

  1. 您可以从市场中使用现有的开源操作之一:

代码语言:javascript
复制
- name: get nested property
    id: format_script
    uses: notiz-dev/github-action-json-property@release
    with: 
        path: 'yourjson.json'
        prop_path: 'status.azure.resource_name'
- run: echo ${{steps.format_script.outputs.prop}} 

如果不需要文件本身,

  1. 只从整个JSON下载一个属性:

代码语言:javascript
复制
- uses: senmu/download-json-property-action@v1.0.0
  with:
    url: 'https://httpbin.org/json'
    property_path: status.azure.resource_name
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71350206

复制
相关文章

相似问题

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