package jsonxt

  1. Overview
  2. Docs

Module Extended.ProcessSource

Extended supports processing JSON data that conforms to the Json.Extended.json json type.

Sourceval member : string -> [> `Assoc of (string * Json.Extended.json) list ] -> Json.Extended.json

member 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

Sourceval index : int -> [> `List of Json.Extended.json list ] -> Json.Extended.json

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

Sourceval 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

Sourceval to_assoc : [> `Assoc of (string * Json.Extended.json) list ] -> (string * Json.Extended.json) list

to_assoc json converts the JSON object `Assoc a to a

Sourceval to_bool : [> `Bool of bool ] -> bool

to_bool json converts `Bool b to b

Sourceval to_bool_option : [> `Bool of bool | `Null ] -> bool option

to_bool_option json converts `Bool b to Some b and `Null to None

Sourceval to_float : [> `Float of float ] -> float

to_float json converts `Float f to f

Sourceval to_float_option : [> `Float of float | `Null ] -> float option

to_float_option json converts `Float f to Some f and `Null to None

Sourceval to_option : ([> `Null ] as 'a -> Json.Extended.json) -> 'a -> Json.Extended.json option

to_option f json returns None if json is `Null otherwise Some (f json).

Sourceval to_list : [> `List of Json.Extended.json list ] -> Json.Extended.json list

to_list json converts `List l to l

Sourceval to_string : [> `String of string ] -> string

to_string json converts `String s to s

Sourceval to_string_option : [> `String of string | `Null ] -> string option

to_string_option json converts `String s to Some s and `Null to None

Sourceval convert_each : (Json.Extended.json -> Json.Extended.json) -> [> `List of Json.Extended.json list ] -> Json.Extended.json list

convert_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.

Sourceval filter_map : ('a -> 'a option) -> 'a list -> 'a list

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.

Sourceval rev_filter_map : ('a -> 'a option) -> 'a list -> 'a list -> 'a list

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

Sourceval flatten : [> `List of 'a list ] list -> 'a list

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

Sourceval rev_flatten : 'a list -> [> `List of 'a list ] list -> 'a list

rev_flatten acc l is the tail recursive version of flatten with the result accumulated in acc. The result is in reverse order.

Sourceval filter_index : int -> [> `List of Json.Extended.json list ] list -> Json.Extended.json list

filter_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]

Sourceval filter_list : [> `List of 'a ] list -> 'a list

filter_list l returns a list of all the values of `List value elements in l

Sourceval filter_assoc : [> `Assoc of 'a ] list -> 'a list

filter_assoc l returns a list of all the values of `Assoc value elements in l

Sourceval filter_bool : [> `Bool of bool ] list -> bool list

filter_bool l returns a list of all the values of `Bool value elements in l

Sourceval filter_float : [> `Float of float ] list -> float list

filter_float l returns a list of all the values of `Float value elements in l

Sourceval filter_string : [> `String of string ] list -> string list

filter_string l returns a list of all the values of `String value elements in l

Sourceval filter_member : string -> [> `Assoc of (string * Json.Extended.json) list ] list -> Json.Extended.json list

filter_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]

Sourceval keys : [> `Assoc of (string * 'a) list ] -> string list

keys assoc returns all the keys from the `Assoc element

Sourceval values : [> `Assoc of (string * 'a) list ] -> 'a list

values assoc returns all the values from the `Assoc element

Sourceval combine : [> `Assoc of 'a list ] -> [> `Assoc of 'a list ] -> [> `Assoc of 'a list ]

combine assoc1 assoc2 appends the associative lists of two `Assoc elements returning an `Assoc element

Sourceval to_number : [> `Int of int | `Float of float ] -> float

to_number json converts `Float f to f and Int i to float i

Sourceval to_number_option : [> `Int of int | `Float of float | `Null ] -> float option

to_number_option json converts `Float f to Some f, `Int i to Some (float i) and `Null to None

Sourceval to_int : [> `Int of int ] -> int

to_int json converts `Int i to i

Sourceval to_int_option : [> `Int of int | `Null ] -> int option

to_int_option json converts `Int i to Some i and `Null to None

Sourceval filter_int : [> `Int of int ] list -> int list

filter_int l returns a list of all the values of `Int value elements in l

Sourceval filter_number : [> `Int of int | `Float of float ] list -> float list
Sourceval sort : [> `Assoc of (string * 'a) list | `List of 'a list | `Tuple of 'a list | `Variant of 'b * 'a option ] as 'a -> 'a

sort 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

OCaml

Innovation. Community. Security.