Module Safe.Util
include Jsonxt__.Process_intf.Shared with type json := json
val member : string -> [> `Assoc of (string * json) list ] -> jsonmember key jsonsearches the JSON objectjson, which must be an`Assocelement, forkeyand returns the value or`Nullif thekeyis missing
val index : int -> [> `List of json list ] -> jsonindex idx jsonreturns theidx-th JSON object in thejsonarray, which must be an`Listelement. A negativeidxvalue starts from the end with -1 being the last element. AFailureexception is raise if the idx is out of bounds
val map : (json -> json) -> [> `List of json list ] -> [> `List of json list ]map f jsonapplies the functionfto each element of the JSON arrayjson, which must be an`Listelement, and returns a`Listelement
val to_assoc : [> `Assoc of (string * json) list ] -> (string * json) listto_assoc jsonconverts the JSON object`Assoc atoa
val to_bool_option : [> `Bool of bool | `Null ] -> bool optionto_bool_option jsonconverts`Bool btoSome band`NulltoNone
val to_float_option : [> `Float of float | `Null ] -> float optionto_float_option jsonconverts`Float ftoSome fand`NulltoNone
val to_option : ([> `Null ] as 'a -> json) -> 'a -> json optionto_option f jsonreturnsNoneifjsonis`NullotherwiseSome (f json).
val to_number_option : [> `Float of float | `Null ] -> float optionto_number_option jsonconverts`Float ftoSome fand`NulltoNone
val to_string_option : [> `String of string | `Null ] -> string optionto_string_option jsonconverts`String stoSome sand`NulltoNone
val convert_each : (json -> json) -> [> `List of json list ] -> json listconvert_each f jsonapplies the functionfto each element of the JSON arrayjson, which must be an`Listelement, and returns a list of the returned values.
val filter_map : ('a -> 'a option) -> 'a list -> 'a listfilter_map f lappliesfto each element of the listland returns a new list with the valuesvfor whichfreturnedSome v.
val rev_filter_map : ('a -> 'a option) -> 'a list -> 'a list -> 'a listrev_filter_map f acc lappliesfto each element of the listland prepends the values for whichfreturnedSome vto listacc.accis 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 listflatten lgiven a list ofjsonelements filters the`Listelements 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 listrev_flatten acc lis the tail recursive version offlattenwith the result accumulated inacc. The result is in reverse order.
val filter_index : int -> [> `List of json list ] list -> json listfilter_index i lreturns thei'th element from each`List l1inl. 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 listfilter_list lreturns a list of all the values of`List valueelements in l
val filter_assoc : [> `Assoc of 'a ] list -> 'a listfilter_assoc lreturns a list of all the values of`Assoc valueelements in l
val filter_bool : [> `Bool of bool ] list -> bool listfilter_bool lreturns a list of all the values of`Bool valueelements in l
val filter_float : [> `Float of float ] list -> float listfilter_float lreturns a list of all the values of`Float valueelements in l
val filter_string : [> `String of string ] list -> string listfilter_string lreturns a list of all the values of`String valueelements in l
val filter_member : string -> [> `Assoc of (string * json) list ] list -> json listfilter_member key jsgiven akeyand 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 listfilter_number lreturns a list of all the values of`Float valueelements in l
val keys : [> `Assoc of (string * 'a) list ] -> string listkeys assocreturns all the keys from the`Assocelement
val values : [> `Assoc of (string * 'a) list ] -> 'a listvalues assocreturns all the values from the`Assocelement
include Jsonxt__.Process_intf.Basic with type json := json
val to_number : [> `Int of int | `Float of float ] -> floatto_number jsonconverts`Float ftofandInt itofloat i
val to_number_option : [> `Int of int | `Float of float | `Null ] -> float optionto_number_option jsonconverts`Float ftoSome f,`Int itoSome (float i)and`NulltoNone
val to_int_option : [> `Int of int | `Null ] -> int optionto_int_option jsonconverts`Int itoSome iand`NulltoNone
include Jsonxt__.Process_intf.Extended with type json := json
val sort : [> `Assoc of (string * 'a) list | `List of 'a list | `Tuple of 'a list | `Variant of 'b * 'a option ] as 'a -> 'asort jsonsorts thejsontree 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