我使用powershell循环通过REST API获得的多个Json文件。但难点在于有些节点并不固定,它们在不同的json体中返回的结果是不同的,通配符似乎没有任何作用。
我的测试Json文件Workflow_Info
如下:
{
"id": "/subscriptions/fcxxxx7/resourceGroups/xxxxxx/providers/Microsoft.Web/sites/xxxx/workflows/Test_email",
"name": "xxxxxxxxx/Test_email",
"type": "Microsoft.Web/sites/workflows",
"kind": "Stateful",
"location": "East Asia",
"properties": {
"files": {
"Test_email/workflow.json": {
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Send_an_email_from_a_shared_mailbox_(V2)": {
"inputs": {
"host": {
"connection": {
"referenceName": "TheValueIwant"
}
},
"method": "post",
"path": "/v2/SharedMailbox/Mail"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {}
},
"kind": "Stateful"
}
}
}
}
另一个Json body是:
{
"id": "/subscriptions/xxx/resourceGroups/xxxx/providers/Microsoft.Web/sites/xxx/workflows/test_email",
"name": "xxx/test_email",
"type": "Microsoft.Web/sites/workflows",
"kind": "Stateful",
"location": "East Asia",
"properties": {
"files": {
"Test_email/workflow.json": {
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {},
"foreach": "@triggerBody()?['attachments']",
"runAfter": {},
"type": "Foreach"
}
},
"contentVersion": "1.0.0.1",
"outputs": {},
"triggers": {
"When_a_new_email_arrives_in_a_shared_mailbox_(V2)": {
"inputs": {
"host": {
"connection": {
"referenceName": "office365"
}
},
"method": "get"
},
"recurrence": {},
"splitOn": "@triggerBody()?['value']",
"type": "ApiConnection"
}
}
},
"kind": "Stateful"
}
},
"flowState": "Disabled",
"health": {
"state": "Healthy"
}
}
}
我想获取的是节点referenceName的值。
但是节点在不同的json中有不同的值,对于第一个Json,我可以通过下面的方法得到它:
$referenceName= $Workflow_Info.properties.files."Test_email/workflow.json".definition.actions.Send_an_email_from_a_shared_mailbox_(V2).inputs.host.connection.referenceName
但是对于第二个Json,我必须将节点更改为:
$referenceName= $Workflow_Info.properties.files."Test_email/workflow.json".definition.triggers.When_a_new_email_arrives_in_a_shared_mailbox_(V2).inputs.host.connection.referenceName
其中2个节点不同:一个是**.actions.Send_an_email_from_a_shared_mailbox_(V2).
,另一个是.triggers.When_a_new_email_arrives_in_a_shared_mailbox_(V2).
**。
**如何使用通用语法获取最终节点?**我无法为每个json文件单独指定节点路径,因为我有数百个json文件。
我尝试使用通配符*
,但不工作。
$referenceName= $Workflow_Info.properties.files."Test_email/workflow.json".definition.actions.'*'.inputs.host.connection.referenceName
1条答案
按热度按时间w8biq8rn1#
假设您要查找的属性的名称始终为
connection
,并且它始终嵌套在definition
属性中,则以下方法应该适用。使用正在讨论的示例,并假设它们存储在$json1
和$json2
中,结果将是TheValueIwant
和office365
。从理论上讲,如果Jsons总是具有相同的结构,那么您可以将
$json
而不是$json.properties.files.'Test_email/workflow.json'.definition
入队,它应该会找到您正在寻找的值,但值得注意的是,此代码并没有处理可能的数组。