package jsonxt
Module Extended.ProcessSource
Extended supports processing JSON data that conforms to the Json.Extended.json json type.
val member :
string ->
[> `Assoc of (string * Json.Extended.json) list ] ->
Json.Extended.jsonmember key json searches the JSON object json, which must be an `Assoc element, for key and returns the value or `Null if the key is missing
index idx json returns the idx-th JSON object in the json array, which must be an `List element. A negative idx value starts from the end with -1 being the last element. A Failure exception is raise if the idx is out of bounds
val map :
(Json.Extended.json -> Json.Extended.json) ->
[> `List of Json.Extended.json list ] ->
[> `List of Json.Extended.json list ]map f json applies the function f to each element of the JSON array json, which must be an `List element, and returns a `List element
val to_assoc :
[> `Assoc of (string * Json.Extended.json) list ] ->
(string * Json.Extended.json) listto_assoc json converts the JSON object `Assoc a to a
to_bool json converts `Bool b to b
to_bool_option json converts `Bool b to Some b and `Null to None
to_float json converts `Float f to f
to_float_option json converts `Float f to Some f and `Null to None
to_option f json returns None if json is `Null otherwise Some (f json).
to_list json converts `List l to l
to_string json converts `String s to s
to_string_option json converts `String s to Some s and `Null to None
val convert_each :
(Json.Extended.json -> Json.Extended.json) ->
[> `List of Json.Extended.json list ] ->
Json.Extended.json listconvert_each f json applies the function f to each element of the JSON array json, which must be an `List element, and returns a list of the returned values.
filter_map f l applies f to each element of the list l and returns a new list with the values v for which f returned Some v.
rev_filter_map f acc l applies f to each element of the list l and prepends the values for which f returned Some v to list acc. acc is returned as the result and is in reverse order to the input. This is a tail call optimised version of filter_map
flatten l given a list of json elements filters the `List elements and flattens them into a single list. This is the same as filter_list |> List.flatten
rev_flatten acc l is the tail recursive version of flatten with the result accumulated in acc. The result is in reverse order.
val filter_index :
int ->
[> `List of Json.Extended.json list ] list ->
Json.Extended.json listfilter_index i l returns the i'th element from each `List l1 in l. Thus,
[[`List [`Int 2; `Int 3]; `List [`Int 4; `Int 5]] |> filter_index 1]returns [`Int 3; `Int 5]
filter_list l returns a list of all the values of `List value elements in l
filter_assoc l returns a list of all the values of `Assoc value elements in l
filter_bool l returns a list of all the values of `Bool value elements in l
filter_float l returns a list of all the values of `Float value elements in l
filter_string l returns a list of all the values of `String value elements in l
val filter_member :
string ->
[> `Assoc of (string * Json.Extended.json) list ] list ->
Json.Extended.json listfilter_member key js given a key 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]
keys assoc returns all the keys from the `Assoc element
values assoc returns all the values from the `Assoc element
combine assoc1 assoc2 appends the associative lists of two `Assoc elements returning an `Assoc element
to_number json converts `Float f to f and Int i to float i
to_number_option json converts `Float f to Some f, `Int i to Some (float i) and `Null to None
to_int json converts `Int i to i
to_int_option json converts `Int i to Some i and `Null to None
filter_int l returns a list of all the values of `Int value elements in l
val sort :
([> `Assoc of (string * 'a) list
| `List of 'a list
| `Tuple of 'a list
| `Variant of 'b * 'a option ] as 'a) ->
'asort json sorts the json tree based on field names. Objects and lists are sorted recursively. Note that the function only sorts field names and not the values. The sort is stable