Json — API reference

3/3 types documented. Of 16 public methods, 2 carry their own description, 14 are covered by their type's, and 0 have neither. An entry with no prose below its signature is undocumented in the source, not undocumented here.

CLASS Codec

Json::Codec.parse(text) is the intuitive entry point (the analog of serde_json::from_str / JSON.parse): it drives a streaming JsonReader over the text into a DataValueBuilder sink, yielding a DataValue DOM tree. The DOM is thus built on the ONE streaming reader — there is no separate tree parser — which is exactly the read-side unification the serde design calls for (the same JsonReader feeds a synthesized typed sink for treeless reconstruct). Codec.serialize(value) is the mirror: it drives the value's serialize events through a JsonWriter and returns compact RFC-8259 text. Both are tiny forwarders — the real work lives in the streaming backends (JsonReader / JsonWriter) and on the data (DataValue.serialize).

Codec is a standalone NAMESPACE (methods + constants only, no instance data, no inheritance/interface). Its name is distinct from MODULE Json, so the cross-module surface is Json::Codec.parse(...) — no Json::Json collision. The JsonReader engine stays available directly for advanced use (streaming into a custom sink) later.

Json/src/Codec.ev:30

Methods

METHOD parseValue(String text) RETURNS | DataValue

Parse a complete JSON document into the untyped DOM. SUCCESS yields the fully-formed DataValue tree; FAILURE carries a message with the error position. The streaming JsonReader parses into a DataValueBuilder — the DOM is just the tree-building sink over the one treeless reader.

NAMED parseValue, not parse: parse is the TYPED facade below (parse[T], I.P), and the two would otherwise be the same signature differing only by return type — which Envzn does not overload on. The split is also what serde_design §8.1 intends: parse[T] names a type, parseValue is the no-type-named DOM read.

METHOD serialize(DataValue value) RETURNS | String

Serialize a DataValue to compact RFC-8259 JSON text. Drives the value's own serialize event stream through a JsonWriter — no intermediate tree walk beyond the value's own structure.

METHOD parse(String text) RETURNS | T
METHOD parseStrict(String text) RETURNS | T

CLASS JsonReader

IMPLEMENTS Deserializer

The streaming JSON Deserializer backend (treeless).

A JsonReader owns a cursor over the input text and, on deserialize, parses the JSON and pushes a flat event stream (put-scalar / beginArray / putKey / beginObject / …) straight into a Serializer sink — it never builds a DOM of its own. The sink decides what the events become: a DataValueBuilder rebuilds a DataValue tree (the untyped DOM path, now JsonReader → DataValueBuilder), a JsonWriter transcodes to text, and a synthesized typed sink (3D) reconstructs an object directly.

The reader recurses INTERNALLY (its own private parse*Into methods, threading the sink param down) rather than handing out sub-readers — the shape Envzn's memory floor admits (no stored mutable borrow, no SELF). It owns its cursor as plain fields and mutates them through its own MODIFY methods; the sink is a plain Serializer param whose MODIFY methods it drives. FAILURE messages carry the line/column of the offending position.

Json/src/JsonReader.ev:28

Constructors

INIT(String source)

Methods

MODIFY METHOD deserialize(Serializer sink) RETURNS STATUS
METHOD atEnd() RETURNS boolean

CLASS JsonWriter

IMPLEMENTS Serializer

The Json module's streaming Serializer backend.

A JsonWriter IS-A kernel Serializer: it receives a flat event stream (put-scalar / beginObject / putKey / endObject / beginArray / endArray) and renders it directly to compact RFC-8259 JSON text — no intermediate tree. value->serialize(writer) on any Serializable (including DataValue) drives it; Codec.serialize(value) wraps that into a one-call façade. This is the "treeless" serialize path: the writer never materialises a DOM, it just streams characters as the events arrive.

Separator bookkeeping is per-nesting-level: each open container is a JsonFrame tracking whether an element has already been emitted (so the next one gets a leading ','). Object entries carry their own separator in putKey; array elements get theirs in preValue.

NB: output accumulates in a DynamicString (JSON text is Unicode). A later optimisation may stream UTF-8 bytes straight into a DynamicByteBuffer to skip the char32 intermediate; the event interface is unchanged by that.

Json/src/JsonWriter.ev:30

Constructors

INIT()

Methods

MODIFY METHOD putNull() RETURNS STATUS
MODIFY METHOD putBool(boolean v) RETURNS STATUS
MODIFY METHOD putNumber(number v) RETURNS STATUS
MODIFY METHOD putString(String v) RETURNS STATUS
MODIFY METHOD putKey(String key) RETURNS STATUS
MODIFY METHOD beginArray() RETURNS STATUS
MODIFY METHOD beginObject() RETURNS STATUS
MODIFY METHOD endArray() RETURNS STATUS
MODIFY METHOD endObject() RETURNS STATUS
METHOD result() RETURNS String