package reddit_api_kernel
Module Reddit_api_kernel.JsonSource
include module type of struct include Ezjsonm end
Basic types
type value = [ | `Null| `Bool of bool| `Float of float| `String of string| `A of value list| `O of (string * value) list
]JSON fragments.
Cast a JSON well-formed document into a JSON fragment.
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.
unwrap t is the reverse of wrap. It expects t to be a singleton JSON object and it return the unique element.
Reading JSON documents and values
Read a JSON document from an input channel.
Read a JSON document from a string.
Read a JSON value from an input channel.
Low-level function to read directly from a Jsonm source.
Reading JSON documents and values -- with proper errors
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.
type read_value_error = [ | `Error of error_location * Jsonm.error| `Unexpected of [ `Lexeme of error_location * Jsonm.lexeme * string | `End_of_input ]
]A human-readable description of an error -- without using the error location.
If the error is attached to a specific location in the buffer, return this location.
val from_channel_result :
in_channel ->
([> {t}1/shadowed/(0964a736b30901763d0083f6f52e82a8) ], [> read_error ])
resultSee from_channel.
val from_string_result :
string ->
([> {t}1/shadowed/(0964a736b30901763d0083f6f52e82a8) ], [> read_error ])
resultSee from_string.
See value_from_channel.
See value_from_string.
See value_from_src.
Writing JSON documents and values
val to_channel :
?minify:bool ->
out_channel ->
[ `A of value list | `O of (string * value) list ] ->
unitWrite a JSON document to an output channel.
val to_buffer :
?minify:bool ->
Buffer.t ->
[ `A of value list | `O of (string * value) list ] ->
unitWrite a JSON document to a buffer.
Write a JSON document to a string. This goes via an intermediate buffer and so may be slow on large documents.
Write a JSON value to an output channel.
Write a JSON value to a buffer.
Write a JSON value to a string. This goes via an intermediate buffer and so may be slow on large documents.
Low-level function to write directly to a Jsonm destination.
Constructors
Same as `A [`String s1; ..; `String sn].
Build a list of values.
Build a dictionnary.
val pair :
('a -> value) ->
('b -> value) ->
('a * 'b) ->
[> {t}1/shadowed/(0964a736b30901763d0083f6f52e82a8) ]Build a pair.
val triple :
('a -> value) ->
('b -> value) ->
('c -> value) ->
('a * 'b * 'c) ->
[> {t}1/shadowed/(0964a736b30901763d0083f6f52e82a8) ]Build a triple.
Accessors
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.
Extract the elements from a dictionnary document.
Extract the triple.
High-level functions
mem v path is true if the given path is valid for the JSON document v.
Find the sub-document addressed by the given path. Raise Not_found if the path is invalid.
Find the sub-document addressed by the given path. Returns None if the path is invalid.
Update the sub-document addressed by the given path. If the provided value is None, then removes the sub-document.
Apply a given function to a subdocument.
Convert a (possibly non-valid UTF8) string to a JSON object.
Convert a JSON object to a (possibly non-valid UTF8) string. Return None if the JSON object is not a valid string.
Convert a JSON object to a (possibly non-valid UTF8) string.
Convert a JSON fragment to an S-expression.
An alias of to_sexp
Convert an S-expression to a JSON fragment
AN alias of of_sexp
Error handling
val 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.sizerval 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.writerval 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.writerval __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 'aval 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.readerval 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.readerval 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