cancel
Showing results for 
Search instead for 
Did you mean: 

How to Convert Object with Key Values Pairs to Array of key values Pairs

vaidyarm
Contributor

This issue I face a lot of times and there is no simple solution I have found so far, let me know if anyone is able to do it 🙂

Input:

{
   "quotes":{
      "USDAED":3.673325,
      "USDAFN":63.849999,
      "USDALL":124.388,
      "USDAMD":476.287499,
      "USDANG":1.788825,
      "USDAOA":135.371665
   }
}

Output :

{
   "quotes":[
      {"USDAED":3.673325},
      {"USDAFN":63.849999},
      {"USDALL":124.388},
      {"USDAMD":476.287499},
      {"USDANG":1.788825},
      {"USDAOA":135.371665}
   ]
}
2 REPLIES 2

j_angelevski
Contributor III

Hi @vaidyarm ,

You can do this with a simple expression in a mapper.

$quotes.entries().map(val => {...[val]})

Target path: $quotes

Input:

    {
        "quotes": {
            "USDAED": 3.673325,
            "USDAFN": 63.849999,
            "USDALL": 124.388,
            "USDAMD": 476.287499,
            "USDANG": 1.788825,
            "USDAOA": 135.371665
        }
    }

Result:

  {
    "quotes": [
      {
        "USDAED": 3.673325
      },
      {
        "USDAFN": 63.849999
      },
      {
        "USDALL": 124.388
      },
      {
        "USDAMD": 476.287499
      },
      {
        "USDANG": 1.788825
      },
      {
        "USDAOA": 135.371665
      }
    ]
  }

image

Superb !!! worked exactly how I needed it, Thanks a lot !! 🙂