package reddit_api_kernel

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Reddit_api_kernel.JsonSource

include module type of struct include Ezjsonm end

Basic types

Sourcetype value = [
  1. | `Null
  2. | `Bool of bool
  3. | `Float of float
  4. | `String of string
  5. | `A of value list
  6. | `O of (string * value) list
]

JSON fragments.

Sourceval value : [ `A of value list | `O of (string * value) list ] -> value

Cast a JSON well-formed document into a JSON fragment.

Sourceval wrap : value -> [> {t}1/shadowed/(3576def1e48fda9bdc1d80c0b8403183) ]

wrap v wraps the value v into a JSON array. To use when it is not possible to statically know that v is a value JSON value.

Sourceval unwrap : [ `A of value list | `O of (string * value) list ] -> value

unwrap t is the reverse of wrap. It expects t to be a singleton JSON object and it return the unique element.

Sourceval from_channel : in_channel -> [> {t}1/shadowed/(3576def1e48fda9bdc1d80c0b8403183) ]

Reading JSON documents and values

Read a JSON document from an input channel.

Sourceval from_string : string -> [> {t}1/shadowed/(3576def1e48fda9bdc1d80c0b8403183) ]

Read a JSON document from a string.

Sourceval value_from_channel : in_channel -> value

Read a JSON value from an input channel.

Sourceval value_from_string : string -> value

Read a JSON value from a string.

Sourceval value_from_src : Jsonm.src -> value

Low-level function to read directly from a Jsonm source.

Reading JSON documents and values -- with proper errors

Sourcetype error_location = (int * int) * (int * int)

Error locations in a source document follow the Jsonm representation of pairs of pairs ((start_line, start_col), (end_line, end_col)) with 0-indexed lines and 1-indexed columns.

Sourcetype read_value_error = [
  1. | `Error of error_location * Jsonm.error
  2. | `Unexpected of [ `Lexeme of error_location * Jsonm.lexeme * string | `End_of_input ]
]
Sourcetype read_error = [
  1. | read_value_error
  2. | `Not_a_t of value
]
Sourceval read_error_description : [< read_error ] -> string

A human-readable description of an error -- without using the error location.

Sourceval read_error_location : [< read_error ] -> error_location option

If the error is attached to a specific location in the buffer, return this location.

Sourceval from_channel_result : in_channel -> ([> {t}1/shadowed/(3576def1e48fda9bdc1d80c0b8403183) ], [> read_error ]) result
Sourceval from_string_result : string -> ([> {t}1/shadowed/(3576def1e48fda9bdc1d80c0b8403183) ], [> read_error ]) result
Sourceval value_from_channel_result : in_channel -> (value, [> read_value_error ]) result
Sourceval value_from_string_result : string -> (value, [> read_value_error ]) result
Sourceval value_from_src_result : Jsonm.src -> (value, [> read_value_error ]) result

Writing JSON documents and values

Sourceval to_channel : ?minify:bool -> out_channel -> [ `A of value list | `O of (string * value) list ] -> unit

Write a JSON document to an output channel.

Sourceval to_buffer : ?minify:bool -> Buffer.t -> [ `A of value list | `O of (string * value) list ] -> unit

Write a JSON document to a buffer.

Sourceval to_string : ?minify:bool -> [ `A of value list | `O of (string * value) list ] -> string

Write a JSON document to a string. This goes via an intermediate buffer and so may be slow on large documents.

Sourceval value_to_channel : ?minify:bool -> out_channel -> value -> unit

Write a JSON value to an output channel.

Sourceval value_to_buffer : ?minify:bool -> Buffer.t -> value -> unit

Write a JSON value to a buffer.

Sourceval value_to_string : ?minify:bool -> value -> string

Write a JSON value to a string. This goes via an intermediate buffer and so may be slow on large documents.

Sourceval value_to_dst : ?minify:bool -> Jsonm.dst -> value -> unit

Low-level function to write directly to a Jsonm destination.

Constructors

Sourceval unit : unit -> value

Same as `Null.

Sourceval bool : bool -> value

Same as `Bool b.

Sourceval string : string -> value

Same as `String s.

Sourceval strings : string list -> [> {t}1/shadowed/(3576def1e48fda9bdc1d80c0b8403183) ]

Same as `A [`String s1; ..; `String sn].

Sourceval int : int -> value

Same as `Float (float_of_int i).

Sourceval int32 : int32 -> value

Same as `Float (Int32.to_float i)

Sourceval int64 : int64 -> value

Same as `Float (Int64.to_float i)

Sourceval float : float -> value

Some as `Float f.

Sourceval list : ('a -> value) -> 'a list -> [> {t}1/shadowed/(3576def1e48fda9bdc1d80c0b8403183) ]

Build a list of values.

Sourceval option : ('a -> value) -> 'a option -> value

Either `Null or a JSON value.

Sourceval dict : (string * value) list -> [> {t}1/shadowed/(3576def1e48fda9bdc1d80c0b8403183) ]

Build a dictionnary.

Sourceval pair : ('a -> value) -> ('b -> value) -> ('a * 'b) -> [> {t}1/shadowed/(3576def1e48fda9bdc1d80c0b8403183) ]

Build a pair.

Sourceval triple : ('a -> value) -> ('b -> value) -> ('c -> value) -> ('a * 'b * 'c) -> [> {t}1/shadowed/(3576def1e48fda9bdc1d80c0b8403183) ]

Build a triple.

Accessors

Sourceexception Parse_error of value * string

All the following accessor functions expect the provided JSON document to be of a certain kind. In case this is not the case, Parse_error is raised.

Sourceval get_unit : value -> unit

Check that the JSON document is `Null.

Sourceval get_bool : value -> bool

Extract b from `Bool b.

Sourceval get_string : value -> string

Extract s from `String s.

Sourceval get_strings : value -> string list

Extract s1;..;sn from `A [`String s1; ...; `String sn].

Sourceval get_int : value -> int

Extract an integer.

Sourceval get_int32 : value -> int32

Extract a 32-bits integer.

Sourceval get_int64 : value -> int64

Extract a 64-bits integer.

Sourceval get_float : value -> float

Extract a float.

Sourceval get_list : (value -> 'a) -> value -> 'a list

Extract elements from a JSON array.

Sourceval get_option : (value -> 'a) -> value -> 'a option

Extract an optional document.

Sourceval get_dict : value -> (string * value) list

Extract the elements from a dictionnary document.

Sourceval get_pair : (value -> 'a) -> (value -> 'b) -> value -> 'a * 'b

Extract the pair.

Sourceval get_triple : (value -> 'a) -> (value -> 'b) -> (value -> 'c) -> value -> 'a * 'b * 'c

Extract the triple.

High-level functions

Sourceval mem : value -> string list -> bool

mem v path is true if the given path is valid for the JSON document v.

Sourceval find : value -> string list -> value

Find the sub-document addressed by the given path. Raise Not_found if the path is invalid.

Sourceval find_opt : value -> string list -> value option

Find the sub-document addressed by the given path. Returns None if the path is invalid.

Sourceval update : value -> string list -> value option -> value

Update the sub-document addressed by the given path. If the provided value is None, then removes the sub-document.

Sourceval map : (value -> value option) -> value -> string list -> value

Apply a given function to a subdocument.

Sourceval encode_string : string -> value

Convert a (possibly non-valid UTF8) string to a JSON object.

Sourceval decode_string : value -> string option

Convert a JSON object to a (possibly non-valid UTF8) string. Return None if the JSON object is not a valid string.

Sourceval decode_string_exn : value -> string

Convert a JSON object to a (possibly non-valid UTF8) string.

Sourceval to_sexp : value -> Sexplib0.Sexp.t

Convert a JSON fragment to an S-expression.

Sourceval sexp_of_value : value -> Sexplib0.Sexp.t

An alias of to_sexp

Sourceval of_sexp : Sexplib0.Sexp.t -> value

Convert an S-expression to a JSON fragment

Sourceval value_of_sexp : Sexplib0.Sexp.t -> value

AN alias of of_sexp

Error handling

Sourceval parse_error : value -> ('a, unit, string, 'b) format4 -> 'a

Raise Parse_error

Sourcetype t = [
  1. | `Null
  2. | `Bool of bool
  3. | `Float of float
  4. | `String of string
  5. | `A of t list
  6. | `O of (string * t) list
]
Sourceval __t_of_sexp__ : Sexplib0.Sexp.t -> t
Sourceval t_of_sexp : Sexplib0.Sexp.t -> t
Sourceval sexp_of_t : t -> Sexplib0.Sexp.t
Sourceval bin_shape_t : Core_kernel.Bin_prot.Shape.t
Sourceval bin_size_t : ([> `A of 'a Core__.Import.list | `Bool of Core__.Import.bool | `Float of Core__.Import.float | `O of (Core__.Import.string * 'a) Core__.Import.list | `String of Core__.Import.string ] as 'a) Bin_prot.Size.sizer
Sourceval bin_write_t : ([< `A of 'a Core__.Import.list | `Bool of Core__.Import.bool | `Float of Core__.Import.float | `Null | `O of (Core__.Import.string * 'a) Core__.Import.list | `String of Core__.Import.string ] as 'a) Bin_prot.Write.writer
Sourceval bin_writer_t : ([< `A of 'a Core__.Import.list | `Bool of Core__.Import.bool | `Float of Core__.Import.float | `Null | `O of (Core__.Import.string * 'a) Core__.Import.list | `String of Core__.Import.string A Bool Float O String ] as 'a) Core_kernel.Bin_prot.Type_class.writer
Sourceval __bin_read_t__ : Bin_prot.Common.buf -> pos_ref:Bin_prot.Common.pos_ref -> int -> [> `A of 'a Core__.Import.list | `Bool of Core__.Import.bool | `Float of Core__.Import.float | `Null | `O of (Core__.Import.string * 'a) Core__.Import.list | `String of Core__.Import.string ] as 'a
Sourceval bin_read_t : ([> `A of 'a Core__.Import.list | `Bool of Core__.Import.bool | `Float of Core__.Import.float | `Null | `O of (Core__.Import.string * 'a) Core__.Import.list | `String of Core__.Import.string ] as 'a) Bin_prot.Read.reader
Sourceval bin_reader_t : ([> `A of 'a Core__.Import.list | `Bool of Core__.Import.bool | `Float of Core__.Import.float | `Null | `O of (Core__.Import.string * 'a) Core__.Import.list | `String of Core__.Import.string ] as 'a) Core_kernel.Bin_prot.Type_class.reader
Sourceval bin_t : ([ `A of 'a Core__.Import.list | `Bool of Core__.Import.bool | `Float of Core__.Import.float | `Null | `O of (Core__.Import.string * 'a) Core__.Import.list | `String of Core__.Import.string ] as 'a) Core_kernel.Bin_prot.Type_class.t
Sourceval of_string : string -> [> {t}1/shadowed/(3576def1e48fda9bdc1d80c0b8403183) ] Core_kernel.Or_error.t
Sourceval get_map : Ezjsonm.value -> Ezjsonm.value Core_kernel.String.Map.t
OCaml

Innovation. Community. Security.