Skip to content

Custom encoding of variants #27

@kit-ty-kate

Description

@kit-ty-kate

Hi,

I've the following json format to parse:
I can have either:

{"type":"address", "content":string}

or:

{"type":"coord", "content":{"latitude":float, "longitude":float}}

And what I would like to do is something like that:

type geo_coord =
  { latitude : float
  ; longitude : float
  } [@@deriving yojson]

type coord =
  | Adresse [@name "address"] of string
  | GeoCoordinates [@name "coord"] of geo_coord
  [@@deriving yojson]
  [@@deriving_field_name "type"]

Is it already possible to do something like that or otherwise, is it possible to add such a feature ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions