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) result

string json ~pointer extracts the value at pointer and decodes it as a string.

val int : string -> pointer:string -> (int, string) result

int json ~pointer extracts the value at pointer and decodes it as an int.

val int64 : string -> pointer:string -> (int64, string) result

int64 json ~pointer extracts the value at pointer and decodes it as an int64.

val float : string -> pointer:string -> (float, string) result

float json ~pointer extracts the value at pointer and decodes it as a float.

val bool : string -> pointer:string -> (bool, string) result

bool json ~pointer extracts the value at pointer and decodes it as a bool.

val is_null : string -> pointer:string -> (bool, string) result

is_null json ~pointer checks whether the value at pointer is null.

val at : 'a Codec.t -> string -> pointer:string -> ('a, string) result

at 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) result

Bigstring variant of string.

val int_bigstring : 
  Raw.buffer ->
  len:int ->
  pointer:string ->
  (int, string) result

Bigstring variant of int.

val int64_bigstring : 
  Raw.buffer ->
  len:int ->
  pointer:string ->
  (int64, string) result

Bigstring variant of int64.

val float_bigstring : 
  Raw.buffer ->
  len:int ->
  pointer:string ->
  (float, string) result

Bigstring variant of float.

val bool_bigstring : 
  Raw.buffer ->
  len:int ->
  pointer:string ->
  (bool, string) result

Bigstring variant of bool.

val is_null_bigstring : 
  Raw.buffer ->
  len:int ->
  pointer:string ->
  (bool, string) result

Bigstring variant of is_null.

val at_bigstring : 
  'a Codec.t ->
  Raw.buffer ->
  len:int ->
  pointer:string ->
  ('a, string) result

Bigstring variant of at.