4

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?

dreftymac
  • 31,404
  • 26
  • 119
  • 182
Lance
  • 592
  • 2
  • 7
  • 13

2 Answers2

22

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']))

Szymon Wylezol
  • 1,446
  • 9
  • 10
  • You are absolutely correct, thank you Szymon. I stumbles upon the error while I was trying to use an azure function to return a json array. Hopefully this helps someone else. – Lance Aug 04 '16 at 17:01
0
 json(decodeBase64(body('HTTP')?['$Content']))

enter image description here

ouflak
  • 2,458
  • 10
  • 44
  • 49