Skip to main content

Module json

Module json 

Source
Expand description

Native json module for JSON parsing and serialization.

Exports: json.parse(text), json.stringify(value, pretty?), json.is_valid(text)

parse(text) always returns a typed Json enum value. The legacy json_value_to_nanboxed untyped fallback was removed in sweep phase 4a. Schema-driven parsing (__parse_typed) coerces JSON directly into a TypedObject for the supplied schema; nested unknown objects fall back to the typed Json enum rather than an untyped HashMap.

Phase-2d strict-typing migration status (Stage D close-out batch, 2026-05-07):

  • json.parse(text) -> Result<Json>MIGRATED at Stage D Step 4. Body builds the strict-typed JsonValue enum (crate::json_value::JsonValue) directly from serde_json::Value and wraps with TypedReturn::Ok(ConcreteReturn::JsonValue(...)) per Stage D Step 1’s ConcreteReturn::JsonValue variant addition (commit a022f43). N6 sub-shape (b1) sign-off; closes B1 sub-decision #2 for json.parse.
  • json.__parse_typed(text, schema_id) -> Result<any>MIGRATED at Stage D close-out Step 3. Body builds HeapValue::TypedObject directly from the runtime schema + JSON object via build_typed_object_from_json, then wraps the Arc<HeapValue> in ConcreteReturn::OpaqueTypedObject per close-out Step 2’s variant addition (commit 1bca2c4). N8 sign-off; closes B1 sub-decision #2 for json.__parse_typed. The 5 legacy ValueWord-using helpers (make_json_enum / json_value_to_enum / json_object_to_typed / json_value_to_typed_nb / json_value_to_typed_json_enum) were DELETED at close-out Step 3 — verified call-graph private to __parse_typed before deletion.
  • json.stringify(value: any, pretty?: bool) -> Result<string> — DEFERRED pending N7 (HeapValue→JSON serializer for HTTP / object-output marshal contexts). N7 is the unified workstream covering HTTP post_json/put_json + yaml/toml/msgpack stringify/encode/encode_bytes (6 consumers total). Body uses deleted to_json_value() + would need the N7 serializer.
  • json.is_valid(text) -> bool — Migratable in isolation but kept deferred for per-file atomicity; lands with stringify when N7 sign-off unblocks the residual json cohort.

N7 is supervisor-level; queued for next-session relay batch (see docs/defections.md HashMap-marshal cluster sub-decision queue 2026-05-07 Stage B+D close-out subsection).

Strict-typed helpers serde_json_to_json_value (used by json.parse), build_json_enum_heap_value, build_field_slot_from_json, and build_typed_object_from_json (used by __parse_typed) construct ValueSlots directly from native types via the ValueSlot::from_* primitives — no ValueWord intermediate, no call to nb_to_slot.

Note: nb_to_slot (defined pub(crate) at crate::type_schema::mod) and adjacent slot-construction code in type_schema/mod.rs still cite the deleted ValueWord API. That cleanup is N9 candidate — type_schema/mod.rs slot-construction- layer migration. Tracked separately for next-session pickup; this commit explicitly does NOT touch type_schema/mod.rs (verification gate caught the cross-cutting concern; Option A2 chosen over A1 to preserve per-file atomicity).

Functions§

create_json_module
Create the json module with JSON parsing and serialization functions.