Open
Description
openedon Nov 13, 2021
You can encode a record, and you can encode a map, but you can't encode a map with record keys. You also can't encode Tuples, which seemed to me like it would be the best workaround.
Here's a sandbox illustrating the issue: https://sandbox.mint-lang.com/sandboxes/Cvi4ReudJVxywQ
Workarounds
I tried to work around this by first transforming the map using Map.entries
. This didn't work for me because Tuple types also can't be encoded.
What did work was ultimately to write my own inline JS like so:
json =
data
|> Map.entries
|> Array.map((data : Tuple(Room, String)) { `{room: {id: #{data[0].id}, name: #{data[0].name}}, when: #{data[1]}}` })
|> Object.Encode.array
|> Json.stringify
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment