Repository navigation
Description
Context
Migration step: porting src/rescript/src/api/Client.res to AffineScript-TEA
(roadmap commit b942b9d, [migration-roadmap.rescript-to-affinescript]).
Client.res uses both a JSON decoder (to parse backend responses) and a JSON
encoder (to build request bodies). Without a Json module in AffineScript
neither side of the wire protocol can be expressed.
Gap
ReScript uses RescriptCore's JSON.Decode and JSON.Encode namespaces:
-- Decoding (parsing JSON → typed values)
json->JSON.Decode.object : Option[Dict[JSON.t]]
json->JSON.Decode.string : Option[String]
json->JSON.Decode.float : Option[Float]
json->JSON.Decode.bool : Option[Bool]
json->JSON.Decode.array : Option[Array[JSON.t]]
-- Encoding (typed values → JSON)
JSON.Encode.string(s) : JSON.t
JSON.Encode.object(dict) : JSON.t
JSON.stringify(json) : StringThe rsr-template-repo affinescript/stdlib/ has no Json.affine module.
There is no opaque Json type, no decoder combinators, and no encoder API.
What is needed
A Json module providing at minimum:
-- Opaque JSON value type
type Json
-- Decoders (return Option or Result to handle malformed data)
Json.Decode.object : Json -> Option[Map[String, Json]]
Json.Decode.string : Json -> Option[String]
Json.Decode.int : Json -> Option[Int]
Json.Decode.float : Json -> Option[Float]
Json.Decode.bool : Json -> Option[Bool]
Json.Decode.array : Json -> Option[Array[Json]]
-- Encoders
Json.Encode.string : String -> Json
Json.Encode.object : Map[String, Json] -> Json
Json.stringify : Json -> String
A codec-based approach (e.g. Codec[T] with encode/decode pairs) would
also satisfy this requirement and would align better with AffineScript's type
system.
Closest existing primitive
None. The Result.affine and Option.affine modules handle the shape of
decode results but provide no JSON parsing capability. Deno's built-in
JSON.parse / JSON.stringify could be surfaced via an FFI binding, which
may be the lowest-friction path.
Impact
Blocks: src/rescript/src/api/Client.res (migration step 1).
All request body construction and all response parsing depend on this module.
Activity
hyperpolymath commentedon May 17, 2026
Folded into the AffineScript stdlib AOT epic as a consumer-driven requirement: hyperpolymath/affinescript#128 (see its Downstream requirements section). This primitive is now tracked there as part of the stdlib surface the AOT pipeline (affinescript#135) must compile; the multi-module integration test (affinescript#137) will use the
Client.res-shaped path as its validation target.Per the migration backlog this issue is not worked independently — it stays open as the echidna-side consumer tracker and closes when the
Client.resport lands, not when affinescript#128 does.hyperpolymath commentedon May 27, 2026
Now tracked under parent #117.
hyperpolymath commentedon May 30, 2026
Verified resolved upstream. The AffineScript stdlib ships
json.affine(335 LOC, v0.3):Jsonsum type —affinescript/stdlib/json.affineencode_null,encode_bool,encode_int,encode_float,encode_string,encode_array,encode_objectdecode_null,decode_bool,decode_int,decode_float,decode_string,decode_array,decode_object,get_fieldparse(src: String) -> Option<HpmJsonValue>— Zig FFI bridge tohpm-json-rsrto_json(val: HpmJsonValue) -> Option<Json>— tree-walk to native sum typestringify(j: Json) -> StringObject payloads use
[(String, Json)]— same shape asdict.affine(#64), so a decoded object feedsdict::getdirectly.Caveat: lowercase module name means qualifier-referencing is constrained per the AffineScript
head requires upper_identrule. Useuse json::{Json, encode_object, ...}and unqualified names inClient.resport, or wait for the affinescript-side stdlib rename slice if aJson.foostyle is preferred.