Forum Discussion

SriVinayaga's avatar
SriVinayaga
New Contributor II
7 years ago
Solved

JSON Array transformation

Hi All, I am in requirement to transform JSON Array Object to a simple JSON Object with values in the array as below. I have thought and nothing striking to my mind. Hence any help will be apprecia...
  • tstack's avatar
    7 years ago

    You’re looking for the toObject() method on arrays. The method takes two callbacks, one to turn the array element into the key and one to turn the element into the value. I think the following will do what you want:

    $BrandData.toObject(elem => elem.Source + "-" + elem.SourceBrand, elem => elem.Brand)
    

    I’m also attaching an example pipeline with this expression.
    ArrayToObject_2019_07_26.slp (3.9 KB)