package tezos-protocol-environment
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=ad9e08819871c75ba6f4530b125f7d157799398e4d77a1e6bfea9d91ff37ff55
sha512=c5dc4d40cc09bc6980fbbdb5c2e105bf4252cf9cfcb2b49660b0ebe4dc789f6709ec3b3bf2f87d81580d3eed9521eeb1c960f24d9b14eb0285aaba1f84d10a9b
doc/tezos-protocol-environment.structs/Tezos_protocol_environment_structs/V2/Data_encoding/Json/index.html
Module Data_encoding.Json
Source
include module type of struct include Data_encoding.Json end
type json = [
| `O of (string * json) list
| `Bool of bool
| `Float of float
| `A of json list
| `Null
| `String of string
]
In memory JSON data, compatible with Ezjsonm
.
Encodes raw JSON data (BSON is used for binary).
Encodes a JSON schema (BSON encoded for binary).
Create a Json_encoding.encoding
from an encoding
.
Generate a schema from an encoding
.
construct_seq enc t
is a representation of t
as a sequence of json lexeme (jsonm_lexeme Seq.t
). This sequence is lazy: lexemes are computed on-demand.
val string_seq_of_jsonm_lexeme_seq :
newline:bool ->
chunk_size_hint:int ->
jsonm_lexeme Seq.t ->
string Seq.t
string_seq_of_jsonm_lexeme_seq ~newline ~chunk_size_hint s
is a sequence of strings, the concatenation of which is a valid textual representation of the json value represented by s
. Each string chunk is roughly chunk_size_hint
long (except the last one that may be shorter).
With the newline
parameter set to true
, a single newline character is appended to the textual representation.
Forcing one element of the resulting string sequence forces multiple elements of the underlying lexeme sequence. Once enough lexemes have been forced that roughly chunk_size_hint
characters are needed to represent them, the representation is returned and the rest of the sequence is held lazily.
Note that most chunks split at a lexeme boundary. This may not be true for string literals or float literals, the representation of which may be spread across multiple chunks.
val blit_instructions_seq_of_jsonm_lexeme_seq :
newline:bool ->
buffer:bytes ->
jsonm_lexeme Seq.t ->
(Bytes.t * int * int) Seq.t
blit_instructions_seq_of_jsonm_lexeme_seq ~newline ~buffer json
is a sequence of (buff, offset, length)
such that the concatenation of the sub-strings thus designated represents the json value in text form.
The intended use is to blit each of the substring onto whatever output the consumer decides. In most cases, the Sequence's buff
is physically equal to buffer
. This is not always true and one cannot rely on that fact. E.g., when the json includes a long string literal, the function might instruct the consumer to blit from that literal directly.
This function performs few allocations, especially of fresh strings.
Note that once the next element of the sequence is forced, the blit instructions become invalid: the content of buff
may have been rewritten by the side effect of forcing the next element.
JSON Error.
and path_item = [
| `Field of string
(*A field in an object.
*)| `Index of int
(*An index in an array.
*)| `Star
(*Any / every field or index.
*)| `Next
(*The next element after an array.
*)
]
A set of accessors that point to a location in a JSON object.
exception Cannot_destruct of path * exn
Exception raised by destructors, with the location in the original JSON structure and the specific error.
val print_error :
?print_unknown:(Format.formatter -> exn -> unit) ->
Format.formatter ->
exn ->
unit
Helpers for writing encoders.
Write a JSON document to a string. This goes via an intermediate buffer and so may be slow on large documents.