Azure Logic应用程序 - 带有动态键/名称的解析JSON

发布于 2025-01-24 11:40:30 字数 1522 浏览 0 评论 0原文

只想知道是否以及如何用JSON中的动态名称来解析HTTP响应? 我使用 azure Management API接收托管身份(系统和用户分配的托管身份)接收所有托管身份。 有了一个foreach,我正在迭代结果。

如果资源具有系统分配的托管身份用户分配的托管身份,则响应看起来像这样:

{
  "principalId": "<principalId1>",
  "tenantId": "<tenantId>",
  "type": "SystemAssigned, UserAssigned",
  "userAssignedIdentities": {
    "/subscriptions/<subscriptionId>/resourcegroups/<resourceGroupName>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<userAssignedIdentitiesName>": {
      "principalId": "<principalId2>",
      "clientId": "<clientId>"
    }
  }
}

现在,我想获得&lt; principtalid2&gt;。 Unfortunately, the Name of the object is dynamic related to the scope of the resource /subscriptions//resourcegroups//providers/Microsoft.ManagedIdentity/userAssignedIdentities/< ; userAssignedIdentitiesName&gt;

我如何解析JSON以接收所需的&lt; principalid2&gt;? 对于所有其他响应,我可以轻松地使用数据操作 parse json使用我从HTTP响应中插入的有效载荷。 有没有办法使用通配符?否则,我可以以某种方式选择userAssignedIdenties接收所需值的第一个对象吗?

just want to know if and how I can parse a HTTP response with a dynamic name in a JSON?
I used the Azure Management API to receive the managed identities (system- and user assigned managed identities) to receive all managed identities.
With a foreach I am iterating the results.

If a resource has a system assigned managed identity and user assigned managed identity, the response looks like this:

{
  "principalId": "<principalId1>",
  "tenantId": "<tenantId>",
  "type": "SystemAssigned, UserAssigned",
  "userAssignedIdentities": {
    "/subscriptions/<subscriptionId>/resourcegroups/<resourceGroupName>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<userAssignedIdentitiesName>": {
      "principalId": "<principalId2>",
      "clientId": "<clientId>"
    }
  }
}

Now, I would like to get the <principalId2>.
Unfortunately, the Name of the object is dynamic related to the scope of the resource /subscriptions/<subscriptionId>/resourcegroups/<resourceGroupName>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<userAssignedIdentitiesName>.

enter image description here

How can I parse the JSON to receive the needed <principalId2>?
For all other responses I can easily use the Data operations Parse JSON with the payload I inserted from the HTTP response.
Is there a way to use a wildcard? Otherwise, could I somehow just select the first object of userAssignedIdentities to receive the needed value?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁的新欢旧爱 2025-01-31 11:40:30

好的,这应该对您有用。 的流程

这是我用...

初始json

您的json作为 string ,在解决方案中如何做到这一点可能会略有不同。

初始化Xpath Result

定义为 array ,表达式为...

xpath(xml(json(concat('{ root: ', replace(variables('JSON'), 'PrincipalId', 'principalId'), '}'))), '(//principalId)[2]')

初始化结果

再次有效,但定义为字符串表达式是...

array(xpath(xml(base64ToString(variables('XPath Result')[0]?['$content'])), '//text()'))[0]

最终结果应该是您的价值...

“结果”

Ok, this should work for you. This is the flow I tested with ...

Flow

Initialise JSON

Your JSON as a string, how you do that in your solution may differ slightly.

Initialize XPath Result

Defined as an Array and the expression is ...

xpath(xml(json(concat('{ root: ', replace(variables('JSON'), 'PrincipalId', 'principalId'), '}'))), '(//principalId)[2]')

Initialize Result

A bit more work again but defined as a String and the expression is ...

array(xpath(xml(base64ToString(variables('XPath Result')[0]?['$content'])), '//text()'))[0]

The end result should be your value ...

Result

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文