Module Yojson.Basic.Util


module Util: sig .. end


Utility functions for data access


exception Type_error of string * Yojson.Basic.json
Raised when the JSON value is not of the correct type to support an operation, e.g. member on an `Int. The string message explains the mismatch.
exception Undefined of string * Yojson.Basic.json
Raised when the equivalent JavaScript operation on the JSON value would return undefined. Currently this only happens when an array index is out of bounds.
val (|>) : 'a -> ('a -> 'b) -> 'b
Forward pipe operator; useful for composing JSON access functions without too many parentheses
val member : string -> Yojson.Basic.json -> Yojson.Basic.json
member k obj returns the value associated with the key k in the JSON object obj, or `Null if k is not present in obj.
val index : int -> Yojson.Basic.json -> Yojson.Basic.json
index i arr returns the value at index i in the JSON array arr. Negative indices count from the end of the list (so -1 is the last element).
val map : (Yojson.Basic.json -> Yojson.Basic.json) ->
Yojson.Basic.json -> Yojson.Basic.json
map f arr calls the function f on each element of the JSON array arr, and returns a JSON array containing the results.
val to_assoc : Yojson.Basic.json -> (string * Yojson.Basic.json) list
val to_bool : Yojson.Basic.json -> bool
val to_bool_option : Yojson.Basic.json -> bool option
val to_float : Yojson.Basic.json -> float
val to_float_option : Yojson.Basic.json -> float option
val to_int : Yojson.Basic.json -> int
val to_int_option : Yojson.Basic.json -> int option
val to_list : Yojson.Basic.json -> Yojson.Basic.json list
val to_string : Yojson.Basic.json -> string
val to_string_option : Yojson.Basic.json -> string option
val convert_each : (Yojson.Basic.json -> 'a) -> Yojson.Basic.json -> 'a list
The conversion functions above cannot be used with map, because they do not return JSON values. This convenience function convert_each to_f arr is equivalent to List.map to_f (to_list arr).