From dc01c8e8ad0ef71d7bd45ba5e5c19287c1cbe24b Mon Sep 17 00:00:00 2001 From: Thomas Gazagnaire Date: Tue, 10 Nov 2026 23:48:59 +0100 Subject: [PATCH] json: one home for each value constructor and verb The top level of Json repeated every constructor of Json.Value (null, bool, number and its float alias, int, string, list, member, name, ...), Value repeated the top-level pp, and Json.Codec repeated the top-level decode, decode_exn and encode and the Meta, Path and Sort aliases. Two names for one function split the callers between them. The constructors now live in Json.Value alone, and the codec verbs and the printer of Json.t at the top level alone, as the encoding libraries' layering puts them; every caller in the tree moves to the remaining name. Json_js.to_jstr took a ?preserve it ignored; it is gone. --- lib/jsonb_codec.ml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/jsonb_codec.ml b/lib/jsonb_codec.ml index 46bd8b2..e9918b8 100644 --- a/lib/jsonb_codec.ml +++ b/lib/jsonb_codec.ml @@ -176,13 +176,13 @@ let rec json_at t i depth : Json.t = let payload () = Bytes.sub_string t.C.a p sz in let number s = Json.Number (number_of_text s, Json.Meta.none) in match C.byte t i land 0x0f with - | 0 -> Json.null () - | 1 -> Json.bool true - | 2 -> Json.bool false + | 0 -> Json.Value.null () + | 1 -> Json.Value.bool true + | 2 -> Json.Value.bool false | 3 | 5 -> number (payload ()) | 4 | 6 -> number (Json_text.text_at t i) - | 7 | 10 -> Json.string (payload ()) - | 8 | 9 -> Json.string (C.unescaped (payload ())) + | 7 | 10 -> Json.Value.string (payload ()) + | 8 | 9 -> Json.Value.string (C.unescaped (payload ())) | (11 | 12) as ty -> if depth > C.max_depth then Jsonb_error.fail_too_deep (); let stop = p + sz in @@ -196,15 +196,15 @@ let rec json_at t i depth : Json.t = go next (json_at t j (depth + 1) :: acc) in let vs = go p [] in - if ty = 11 then Json.list vs + if ty = 11 then Json.Value.list vs else let rec members = function | [] -> [] | Json.String (k, _) :: v :: rest -> - Json.member (Json.name k) v :: members rest + Json.Value.member (Json.Value.name k) v :: members rest | _ -> malformed () in - Json.object' (members vs) + Json.Value.object' (members vs) | _ -> malformed () let payload : type a. a t -> C.t -> int -> (int -> bool) -> string = -- knotmirror 0.0.1