Simdjsont.Extract
simdjsont · API reference
Extract values from a JSON string using a JSON pointer.
The ~pointer argument uses JSON Pointer syntax (RFC 6901): "/" separates object fields and array indexes, so "/users/0/name" selects the name field of the first user.
Extraction is useful when you only need a few fields and do not want to define a full record codec.
let json = {|{"user":{"id":1,"name":"Ada"}}|} in
let name = Simdjsont.Extract.string json ~pointer:"/user/name"val string : string -> pointer:string -> (string, string) resultstring json ~pointer extracts the value at pointer and decodes it as a string.
val int : string -> pointer:string -> (int, string) resultint json ~pointer extracts the value at pointer and decodes it as an int.
val int64 : string -> pointer:string -> (int64, string) resultint64 json ~pointer extracts the value at pointer and decodes it as an int64.
val float : string -> pointer:string -> (float, string) resultfloat json ~pointer extracts the value at pointer and decodes it as a float.
val bool : string -> pointer:string -> (bool, string) resultbool json ~pointer extracts the value at pointer and decodes it as a bool.
val is_null : string -> pointer:string -> (bool, string) resultis_null json ~pointer checks whether the value at pointer is null.
val at : 'a Codec.t -> string -> pointer:string -> ('a, string) resultat codec json ~pointer extracts the value at pointer and decodes it using codec. This is useful for typed sub-documents:
let first_user = Simdjsont.Extract.at user_codec json ~pointer:"/users/0"Bigstring variants
Each mirrors the string-based extractor above, taking the first len bytes of a bigstring instead of a string. Parsing is zero-copy when buf is already padded.
val string_bigstring :
Raw.buffer ->
len:int ->
pointer:string ->
(string, string) resultBigstring variant of string.
val int_bigstring :
Raw.buffer ->
len:int ->
pointer:string ->
(int, string) resultBigstring variant of int.
val int64_bigstring :
Raw.buffer ->
len:int ->
pointer:string ->
(int64, string) resultBigstring variant of int64.
val float_bigstring :
Raw.buffer ->
len:int ->
pointer:string ->
(float, string) resultBigstring variant of float.
val bool_bigstring :
Raw.buffer ->
len:int ->
pointer:string ->
(bool, string) resultBigstring variant of bool.
val is_null_bigstring :
Raw.buffer ->
len:int ->
pointer:string ->
(bool, string) resultBigstring variant of is_null.
val at_bigstring :
'a Codec.t ->
Raw.buffer ->
len:int ->
pointer:string ->
('a, string) resultBigstring variant of at.