Page
Library
Module
Module type
Parameter
Class
Class type
Source
Ezjsonm
SourceAn easy interface on top of the Jsonm
library.
This version provides more convenient (but far less flexible) input and output functions that go to and from string
values. This avoids the need to write signal code, which is useful for quick scripts that manipulate JSON.
More advanced users should go straight to the Jsonm
library and use it directly, rather than be saddled with the Ezjsonm interface below.
type value = [
| `Null
| `Bool of bool
| `Float of float
| `String of string
| `A of value list
| `O of (string * value) list
]
JSON fragments.
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 value from an input channel.
Low-level function to read directly from a Jsonm
source.
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.
See from_channel
.
See from_string
.
See value_from_channel
.
See value_from_string
.
See value_from_src
.
Write a JSON document to an output channel.
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.
Build a triple.
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.
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 a JSON object to an S-expression
Convert an S-expression to a JSON fragment
AN alias of of_sexp
Convert an S-expression to a JSON object