Parsing JSON array in Azure Logic App from base64 encoded string to use in For_each

Lance picture Lance · Aug 3, 2016 · Viewed 7.5k times · Source

I am trying to iterate through a JSON array which has been encoded to a string for the purpose of storing on a queue. However, I receive the following error message:

{"code":"ExpressionEvaluationFailed","message":"The execution of template action 'For_each' failed: The result '[{\"Foo\":\"Bar\"}]' of the evaluation of 'foreach' action expression '@{json(decodeBase64(triggerBody()['ContentData']))}' is not a valid array."}

The following is the string being parsed: [{"Foo":"Bar"}]

I have no problems parsing a JSON string when it is not in an array, for example: {"Foo":"Bar"}

This parses just fine when I am not using a For_each.

How do I get the logic app to read this as an array?

Answer

Szymon Wylezol picture Szymon Wylezol · Aug 3, 2016

The issue here is that you are using string interpolation (where expressions are wrapped in @{ ... }) that evaluates to a string representation of the array. Hence evaluation of the 'foreach' expression fails.

You want the expression to be @json(decodeBase64(triggerBody()['ContentData']))