Azure Logic应用程序 - 带有动态键/名称的解析JSON
只想知道是否以及如何用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/
。
我如何解析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>
.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,这应该对您有用。 的流程
这是我用...
初始json
您的json作为 string ,在解决方案中如何做到这一点可能会略有不同。
初始化Xpath Result
定义为 array ,表达式为...
初始化结果
再次有效,但定义为字符串表达式是...
最终结果应该是您的价值...
Ok, this should work for you. This is the flow I tested with ...
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 ...
Initialize Result
A bit more work again but defined as a String and the expression is ...
The end result should be your value ...