Any way of JSON encoding an array with different types for items?

Hi all,

This is the JSON I need to post on the API

[ [ "a", "=", "val"]
, ["b", ">", 6 ]
]

Basically, an array of 3 items arrays that the last value can be any primitive type.

I’m kind of stock looking at JSON.Encode.list and .array not sure I can achieve this.

Any pointers would be highly appreciated. I would guess there’s a way to get that result?

Thanks,
Dominic

Yes, you could use a custom type for the values in the list. Something like this https://ellie-app.com/7QjP7XSyZsfa1

You could probably do something like this ?

import Json.Encode as E

E.list identity [ E.string "b", E.string ">", E.int 6 ]

A nicer implementation using a type for the operations
https://ellie-app.com/7QjWPJTK24ca1

Thanks @Sebastian this really helped.