nkrkv / jzon

ReScript library to encode and decode JSON data with type safety.
https://nkrkv.github.io/jzon/
Other
76 stars 4 forks source link

How to encode and decode a struct which has some fields that are variants? #17

Open Mng12345 opened 1 year ago

Mng12345 commented 1 year ago

As the title, i have a model type t, which's definition is below:

module Product = {
  type t = VideoToGif | GifEditor | GifCompress
}

module Event = {
  type businessPoint = {
    name: string,
    data: Js.Dict.t<string>,
  }
  type t =
    | EnterPage
    | LeavePage
    | BusinessPoint(businessPoint)
}

type t = {
  event: Event.t,
  product: Product.t,
  time: string,
}

How to encode and decode the struct with type t?

Mng12345 commented 1 year ago

I just found the answer in the documentation...... doc

Mng12345 commented 1 year ago

There is still a problem that i don't know how to encode a struct with type Event.t