Module Process.Strict
Strict
supports processing JSON data that conforms to the Json.Strict.json
json type.
include Jsonxt__.Process_intf.Shared with type json := Jsonxt.Json.Strict.json
val member : string -> [> `Assoc of (string * json) list ] -> json
member key json
searches the JSON objectjson
, which must be an`Assoc
element, forkey
and returns the value or`Null
if thekey
is missing
val index : int -> [> `List of json list ] -> json
index idx json
returns theidx
-th JSON object in thejson
array, which must be an`List
element. A negativeidx
value starts from the end with -1 being the last element. AFailure
exception is raise if the idx is out of bounds
val map : (json -> json) -> [> `List of json list ] -> [> `List of json list ]
map f json
applies the functionf
to each element of the JSON arrayjson
, which must be an`List
element, and returns a`List
element
val to_assoc : [> `Assoc of (string * json) list ] -> (string * json) list
to_assoc json
converts the JSON object`Assoc a
toa
val to_bool_option : [> `Bool of bool | `Null ] -> bool option
to_bool_option json
converts`Bool b
toSome b
and`Null
toNone
val to_float_option : [> `Float of float | `Null ] -> float option
to_float_option json
converts`Float f
toSome f
and`Null
toNone
val to_option : ([> `Null ] as 'a -> json) -> 'a -> json option
to_option f json
returnsNone
ifjson
is`Null
otherwiseSome (f json)
.
val to_number_option : [> `Float of float | `Null ] -> float option
to_number_option json
converts`Float f
toSome f
and`Null
toNone
val to_string_option : [> `String of string | `Null ] -> string option
to_string_option json
converts`String s
toSome s
and`Null
toNone
val convert_each : (json -> json) -> [> `List of json list ] -> json list
convert_each f json
applies the functionf
to each element of the JSON arrayjson
, which must be an`List
element, and returns a list of the returned values.
val filter_map : ('a -> 'a option) -> 'a list -> 'a list
filter_map f l
appliesf
to each element of the listl
and returns a new list with the valuesv
for whichf
returnedSome v
.
val rev_filter_map : ('a -> 'a option) -> 'a list -> 'a list -> 'a list
rev_filter_map f acc l
appliesf
to each element of the listl
and prepends the values for whichf
returnedSome v
to listacc
.acc
is returned as the result and is in reverse order to the input. This is a tail call optimised version offilter_map
val flatten : [> `List of 'a list ] list -> 'a list
flatten l
given a list ofjson
elements filters the`List
elements and flattens them into a single list. This is the same asfilter_list |> List.flatten
val rev_flatten : 'a list -> [> `List of 'a list ] list -> 'a list
rev_flatten acc l
is the tail recursive version offlatten
with the result accumulated inacc
. The result is in reverse order.
val filter_index : int -> [> `List of json list ] list -> json list
filter_index i l
returns thei
'th element from each`List l1
inl
. Thus,[[`List [`Int 2; `Int 3]; `List [`Int 4; `Int 5]] |> filter_index 1]
returns
[`Int 3; `Int 5]
val filter_list : [> `List of 'a ] list -> 'a list
filter_list l
returns a list of all the values of`List value
elements in l
val filter_assoc : [> `Assoc of 'a ] list -> 'a list
filter_assoc l
returns a list of all the values of`Assoc value
elements in l
val filter_bool : [> `Bool of bool ] list -> bool list
filter_bool l
returns a list of all the values of`Bool value
elements in l
val filter_float : [> `Float of float ] list -> float list
filter_float l
returns a list of all the values of`Float value
elements in l
val filter_string : [> `String of string ] list -> string list
filter_string l
returns a list of all the values of`String value
elements in l
val filter_member : string -> [> `Assoc of (string * json) list ] list -> json list
filter_member key js
given akey
and a list of json`Assoc
-s,js
, returns the list of values extracted from each of the`Assoc
-s. Thus,[[`Assoc [("id", `Int 1)]; `Assoc [("id", `Int 2)]]] |> filter_member "id"]
returns
[`Int 1; `Int 2]
val filter_number : [> `Float of float ] list -> float list
filter_number l
returns a list of all the values of`Float value
elements in l
val keys : [> `Assoc of (string * 'a) list ] -> string list
keys assoc
returns all the keys from the`Assoc
element
val values : [> `Assoc of (string * 'a) list ] -> 'a list
values assoc
returns all the values from the`Assoc
element