package decoders-jsonm

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Streaming encoding using Jsonm.

Example usage:

module E = Decoders_jsonm.Encode

let run_encoder out_channel (encode : t E.encoder) (x : t) =
  let dst = `Channel out_channel in
  let encoder = Jsonm.encoder ~minify:true dst in
  let env = E.make_env ~encoder () in
  E.encode_value encode x env
type env
val make_env : encoder:Jsonm.encoder -> ?on_partial:(unit -> unit) -> unit -> env
include Decoders.Encode.S with type value = env -> unit
type value = env -> unit
type 'a encoder = 'a -> value
val string : string encoder
val int : int encoder
val float : float encoder
val bool : bool encoder
val null : value
val nullable : 'a encoder -> 'a option encoder
val option : 'a encoder -> 'a option encoder
  • deprecated Use nullable instead.
val list : 'a encoder -> 'a list encoder
val array : 'a encoder -> 'a array encoder
val obj : (string * value) list encoder
val obj' : (value * value) list encoder
val value : value encoder
val of_to_string : ('a -> string) -> 'a encoder
val encode_value : 'a encoder -> 'a -> value
val encode_string : 'a encoder -> 'a -> string

Low-level combinators

Assuming we have:

type member
val member : member encoder

And a type x:

type x =
  { id : string
  ; members : member list
  }

An encoder for x might look like this:

let x_encoder x =
  object_start >>

  name "id" >>
  string x.id >>

  name "members" >>
  array_start >>
  iter member x.members >>
  array_end >>

  object_end
val (>>) : value -> value -> value
val iter : 'a encoder -> 'a list -> value
val object_start : value
val name : string -> value
val object_end : value
val array_start : value
val array_end : value
val end_ : value
OCaml

Innovation. Community. Security.