@std/json.ms#
Import each required symbol with import Name from "@std/json.ms".
JsonError Alternative#
Errors returned for malformed JSON or configured input and nesting limits.
type JsonError:
case InvalidInput
case InvalidData
case LimitExceededimpl Error for JsonError:
fn message() -> String:JsonError.InvalidData#
JSON syntax, Unicode escapes, duplicate keys, number text or a cyclic value is invalid.
case InvalidDataJsonError.InvalidInput#
An explicit input, depth, value-count or output budget is negative.
case InvalidInputJsonError.LimitExceeded#
The input, nesting, value count or encoded output exceeds a supplied budget.
case LimitExceededJsonError.Error.message#
Returns a JSON-prefixed diagnostic without echoing input text or number tokens.
fn message() -> String:JsonLimits Record#
Optional bounds for JSON input bytes, nesting depth, and parsed values.
type JsonLimits:
max_bytes: Optional[Int] = none
max_depth: Optional[Int] = none
max_values: Optional[Int] = noneJsonLimits.max_bytes#
Maximum UTF-8 input bytes before parsing; none adds no input-size budget.
max_bytes: Optional[Int] = noneJsonLimits.max_depth#
Maximum container nesting; a root scalar has depth zero, and a root container depth one.
max_depth: Optional[Int] = noneJsonLimits.max_values#
Maximum parsed containers and scalar values, excluding object keys; none adds no count budget.
max_values: Optional[Int] = noneJsonValue Alternative#
A JSON value. Number text is retained to avoid losing precision during parsing.
type JsonValue:
case Null
case BoolValue(value: Bool)
case NumberValue(text: String)
case StringValue(value: String)
case ArrayValue(values: List[JsonValue])
case ObjectValue(values: Map[String, JsonValue])JsonValue.ArrayValue#
An ordered JSON array whose mutable list can be updated before serialization.
case ArrayValue(values: List[JsonValue])JsonValue.BoolValue#
A JSON true or false value.
case BoolValue(value: Bool)JsonValue.Null#
JSON null, represented without a payload value.
case NullJsonValue.NumberValue#
An exact JSON number token; parsing does not coerce it into Float.
case NumberValue(text: String)JsonValue.ObjectValue#
A JSON object retaining insertion order and rejecting duplicate keys during parsing.
case ObjectValue(values: Map[String, JsonValue])JsonValue.StringValue#
A decoded JSON string, with escapes resolved into Unicode text.
case StringValue(value: String)JsonValue.ArrayValue.values#
Element values in source order; nested mutable payloads retain their references.
values: List[JsonValue]JsonValue.BoolValue.value#
The decoded boolean, without a textual representation requirement.
value: BoolJsonValue.NumberValue.text#
Original numeric token text; stringify validates its JSON number syntax.
text: StringJsonValue.ObjectValue.values#
String-keyed members in insertion order; stringify reads their current values.
values: Map[String, JsonValue]JsonValue.StringValue.value#
Decoded UTF-8 text, preserving scalar contents without normalization.
value: Stringparse Function#
Parses one JSON value and applies the supplied input, depth, and value limits.
fn parse(text: String, limits: Optional[JsonLimits] = none) -> Result[JsonValue, JsonError]:stringify Function#
Serializes a JSON value. max_bytes bounds output when supplied.
fn stringify(value: JsonValue, max_bytes: Optional[Int] = none) -> Result[String, JsonError]: