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

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 :slightly_smiling_face:

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}
   ]
}

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

1 Like

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

1 Like