List with nested maps - Part Deux

I don’t see any lists here. To go from your input to your desired output can be done in a straightforward way:

flattened = %{
  asset: items.amountAsset,
  priced_in: items.priceAsset,
  last: items.data.lastPrice,
  volume: items.data.volumeWaves
}

If you truly do have a list of items, then you’d want to do that inside an Enum.map.

Also, you should not use upper case keys in your maps. Those are reserved for module names and will cause you some problems.

edit: I see you made items a list while I was posing

Enum.map(items, fn item ->
  %{
    asset: item.amountAsset,
    priced_in: item.priceAsset,
    last: item.data.lastPrice,
    volume: item.data.volumeWaves
  }
end)
2 Likes