The error occurs because Azure Logic Apps requires explicit array initialization in certain contexts. Here's the step-by-step solution:
1. Use [] with an Expression Prefix
In Azure Logic Apps, empty array literals must be wrapped in an expression using the @ symbol. For example:
@coalesce(
items('For_each_onderwijsgroep_to_process')?['Voorgesorteerde_x0020_leertrajec'],
@[] // Explicit empty array
)
2. Validate the Entire Expression
If the above fails, check if the property Voorgesorteerde_x0020_leertrajec is truly an array in your input data. If it’s a non-array value (e.g., a string), coalesce will return it, causing downstream errors. Use this defensive check:
@coalesce(
if(
contains(items('For_each_onderwijsgroep_to_process'), 'Voorgesorteerde_x0020_leertrajec')
&& type(items('For_each_onderwijsgroep_to_process')?['Voorgesorteerde_x0020_leertrajec']) == 'Array',
items('For_each_onderwijsgroep_to_process')?['Voorgesorteerde_x0020_leertrajec'],
@[] // Fallback to empty array
),
@[] // Final fallback
)
3. Alternative: Initialize a Variable
If the expression still fails, initialize an empty array variable before the loop and reference it:
-
Add an Initialize variable action:
- Name:
EmptyArray
- Type:
Array
- Value:
[] (empty array).
-
Use the variable in your expression:
@coalesce(
items('For_each_onderwijsgroep_to_process')?['Voorgesorteerde_x0020_leertrajec'],
variables('EmptyArray')
)
Key Takeaway:
- Use
@[] instead of createArray() for empty arrays.
- Ensure the property
Voorgesorteerde_x0020_leertrajec is validated as an array before use.