@decco Variant encoding

Is there an easy way to skip the array on encode?

type order = {
  name: string,

type rule =
  | Order(order)


["Order", {name: "John Smith"}]


{name: "John Smith"}

Not exactly sure how to accomplish this with a custom codec or if that is the best way to achieve this.

Perhaps use order_encode? Note it depends on the full semantics of your actual type and how it needs to be encoded and decoded in the real codebase. From the simplified example it’s not really possible to tell.

Maybe it helps to parse into variant. https://github.com/green-labs/ppx_spice

1 Like