Problem Statement :
How to Replace Nth Index Item of an Array :
Input :
Output :
Prerequisites :
- Azure Data Factory / Synapse
Solution :
GitHUB Code
In Synapse / ADF , it is not possible to self reference a variable in Set Variable Activity. Hence, we would need to create a TempArray variable and then over ride the original array with the TempArray one.
- To Replace the Nth Index Item in an array, we can follow the below option of recreating a new array from the Initial Array :
a) Get elements from 0 index till N-1 Index
b) The Nth Index position would be the Parameter NewValue
c) Get elements from N+1 Index till the last element
@createArray(take(variables('InputArray'),pipeline().parameters.NthIndex),pipeline().parameters.NewValue,skip(variables('InputArray'),add(pipeline().parameters.NthIndex,1)))
Output :
2. To Override the InitialArray variable and get the Array in required format :
@json(concat('[',replace(replace(string(variables('TempArray')), '[', ''),']',''),']'))
Final Output :