mattjbray / ocaml-decoders

Elm-inspired decoders for Ocaml
https://mattjbray.github.io/ocaml-decoders/
Other
84 stars 8 forks source link

How to encode heterogeneous JSON array? #60

Closed dboris closed 1 year ago

dboris commented 1 year ago

Decode has an uncons function which makes it possible to decode a JSON value like the following:

["hello", true, 1]

What is the opposite operation in Encode? How can this value be encoded given an OCaml tuple of type (string bool int)?

mattjbray commented 1 year ago

You can write

list value [string "hello"; bool true; int 1]
dboris commented 1 year ago

Great. Thank you.