My agentic slop goes here. Not intended for anyone else!
at main 986 B view raw
1(* Helper functions for JSON operations in tests using jsont codecs *) 2 3let to_string ?(minify=false) json = 4 let format = if minify then Jsont.Minify else Jsont.Indent in 5 match Jsont_bytesrw.encode_string' ~format Jsont.json json with 6 | Ok s -> s 7 | Error err -> Jsont.Error.to_string err 8 9(* Helper to decode an optional field with a given codec *) 10let get_opt (type a) (codec : a Jsont.t) json key : a option = 11 let field_codec = Jsont.Object.map ~kind:"field" (fun v -> v) 12 |> Jsont.Object.opt_mem key codec ~enc:Fun.id 13 |> Jsont.Object.finish 14 in 15 match Jsont.Json.decode field_codec json with 16 | Ok v -> v 17 | Error _ -> None 18 19let get_string json key = get_opt Jsont.string json key 20let get_int json key = get_opt Jsont.int json key 21let get_bool json key = get_opt Jsont.bool json key 22 23let get_array json key = 24 get_opt (Jsont.list Jsont.json) json key 25 26let as_string json = 27 match Jsont.Json.decode Jsont.string json with 28 | Ok s -> Some s 29 | Error _ -> None