Simdjsont.Decode.Obj
simdjsont · API reference
Builder for JSON objects.
The builder API is driven by a constructor function provided to field, then extended with fields using mem and opt_mem, and finalized with finish.
type ('o, 'dec) builderBuilder state for an object codec.
'o is the resulting OCaml type.
val field : 'a -> ('o, 'a) builderfield constructor starts an object codec from a constructor function. Add one mem or opt_mem per constructor argument, in the same order the constructor expects them.
val mem :
string ->
'a Simdjsont__.Simdjsont_codec.t ->
enc:('o -> 'a) ->
('o, 'a -> 'b) builder ->
('o, 'b) buildermem name codec ~enc builder adds a required member. Decoding fails if name is absent. enc extracts the field value when encoding.
val opt_mem :
string ->
'a Simdjsont__.Simdjsont_codec.t ->
enc:('o -> 'a option) ->
('o, 'a option -> 'b) builder ->
('o, 'b) builderopt_mem name codec ~enc builder adds an optional member. Decoding yields None when the member is absent or null. Encoding omits the member when enc value is None.
val finish : ('o, 'o) builder -> 'o Simdjsont__.Simdjsont_codec.tfinish builder turns a completed object builder into a codec. The final builder type must show that all constructor arguments have been supplied; this is why missing mem / opt_mem calls are usually type errors.