Replace Nth Index Item of an Array via Azure Data Factory / Synapse Pipeline through Regular Expressions

Problem Statement :

How to Replace Nth Index Item of an Array :

Input :

Output :

Prerequisites :

  1. 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.

  1. 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 :

Published by Nandan Hegde

Microsoft Data MVP |Microsoft Data platform Architect | Blogger | MSFT Community Champion I am a MSFT Data Platform MVP and Business Intelligence and Data Warehouse professional working within the Microsoft data platform eco-system which includes Azure Synapse Analytics ,Azure Data Factory ,Azure SQL Database and Power BI. To help people keep up with this ever-changing landscape, I frequently posts on LinkedIn, Twitter and to his blog on https://datasharkx.wordpress.com. LinkedIn Profile : www.linkedin.com/in/nandan-hegde-4a195a66 GitHUB Profile : https://github.com/NandanHegde15 Twitter Profile : @nandan_hegde15 MSFT MVP Profile : https://mvp.microsoft.com/en-US/MVP/profile/8977819f-95fb-ed11-8f6d-000d3a560942

Leave a comment

Design a site like this with WordPress.com
Get started