Home > Enterprise >  Logic App convert data in JSON array to variables
Logic App convert data in JSON array to variables

Time:07-07

I'm creating a Azure Logic App with a Azure function that returns the following JSON

{
"Status": "Ok",
"Message": null,
"Response": {
    "total": 1,
    "data": [
        {
            "employeeID": "123456",
            "userName": "John.Doe",
            "fullName": "John Doe",
            "legalFirstName": "John",
            "legalLastName": "Doe"
        }
    ]
}

}

I'm trying to convert the JSON data to variables to be able to use these in follow-up steps of the Azure Workflow.

For this I added I step to parse the JSON and then initialize a variable. When I add one of the values the Logic Apps embeds the initialize variable step into a for each loop which. I guess because the JSON data returned is in a array.

However, when saving the Logic App following error is returned: "Failed to save logic app RenameTest. The variable action 'Initialize_variable' of type 'InitializeVariable' cannot be nested in an action of type 'For_each'."

How can I convert the JSON data to variables?

enter image description here

enter image description here

CodePudding user response:

Looking at the documentation:

You can create a variable and declare its data type and initial value - all within one action in your logic app. You can only declare variables at the global level, not within scopes, conditions, and loops.

So you would need to create the variables at the beginning of the flow. You can then use the Set variable action inside the loop to assign the variables to the desired values.

  • Related