I use powershell to loop through multiple Json files obtained by the REST API. But the difficulty is that some nodes are not fixed, they are different in different json bodies returned, wildcards seem to have no effect.
My test Json file Workflow_Info
like:
{
"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"
}
}
}
}
And another Json body is:
{
"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"
}
}
}
What I want to get is the value of the node referenceName.
But the node it has different value in different json, for the first Json, I could get it by below:
$referenceName= $Workflow_Info.properties.files."Test_email/workflow.json".definition.actions.Send_an_email_from_a_shared_mailbox_(V2).inputs.host.connection.referenceName
But for the second Json, I have to change the node to:
$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 of these nodes are different:
one is .actions.Send_an_email_from_a_shared_mailbox_(V2).
and another is .triggers.When_a_new_email_arrives_in_a_shared_mailbox_(V2).
.
How to use a common syntax to get the final node? I can't specify the node path for each json file individually, because I have hundreds of json files.
I tried to use wildcard *
, but not work.
$referenceName= $Workflow_Info.properties.files."Test_email/workflow.json".definition.actions.'*'.inputs.host.connection.referenceName