package metadb

  1. Overview
  2. Docs

This is a wrapper for the Yojson library

type t = [
  1. | `Null
  2. | `Bool of bool
  3. | `Int of int
  4. | `Float of float
  5. | `String of string
  6. | `Assoc of (string * t) list
  7. | `List of t list
]

Type of Basic Json values

exception ParsingFailure of string
val get : string -> t -> t option

Get value of a key in a Json association list. Returns none if key is not found. Raises ParsingFailure if not an association list

val get_err : string -> t -> t

Same as get but raises ParsingFailure if key is unbound

val add_entry : string -> t -> t -> t

Add entry to an association list and raise ParsingFailure if not an association list

val remove_entry : string -> t -> t

Remove entry from association list and raise ParsingFailure if not an association list

val to_list : t -> t list

Convert a Json list to a list. Raise ParsingFailure if not a list

val to_int : t -> int

Convert a Json int to an int. Raise ParsingFailure if not an int

val to_string : t -> string

Convert Json string to a string. Raise ParsingFailure if not a string

val to_bool : t -> bool

Convert Json bool to bool. Raise ParsingFailure if not a bool

val raise_opt : string -> [> `Null ] as 'a option -> 'a

Convert t option to t and raise ParsingFailure with message specified by the first argument if None or `Null

val default : 'a -> [> `Null ] as 'a option -> 'a

Convert t option to t and return first argument if None or `Null

val write_string : t -> string

Write Json to string in a compact way

val pretty_to_string : t -> string

Write Json to string in a readable way

val from_string : string -> t

Parse Json from string

val to_file : Path.root -> t -> unit

Write Json to file

val from_file : Path.root -> t

Read Json from file