Parsing json key:value in Data Factory

Viewed 1686

I have a exchange rate API output like such:

enter image description here

I would like get an array to pass through another pipeline as a parameter to iterate over. However I have been fruitless in my endeavors. I would like to have an array of the currencies. In ADF terms I want to set my array variable to the properties of @activity('API Call').output.rates .

I have tried setting @activity('API Call').output.rates to both an array and a string variable (adding string() and array() to the content with out any luck. However, I have been able to set the string variable to @activity('API Call').output.rates.AED/AFN etc, however that is not what I needed. Those curly brackets around rates have got me a little stumped, if they were square brackets no problemo. I've also tried a few goes with string functions to no avail.

Can anyone with familiarity of Azure Dynamic Content push me in the right direction?

2 Answers

I ended up working around this solution by querying a reference table with the keys and iterating over the object. Obviously not the lightest and cleanest solution but it did fit better into my process than utilizing a function or anything like that.

The concession I had to make was that the keys were going to have to be known before hand, but given that new currencies do not pop up often (with the exception of cryptos, which I'm not working with).

Rates is an object... to get an array of the properties inside... you should use javascript's Object.keys() function

var keyArray = Object.keys(@activity('API Call').output.rates);

for(var index = 0; index < keyArray.length; index++){
    var message = 'Value of ' + keyArray[index];
    message += ' is: ' + @activity('API Call').output.rates[keyArray[index]];
    console.log(message);
}
Related