My agentic slop goes here. Not intended for anyone else!
1(* Helper functions for JSON operations in tests *) 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 9let get_field json key = 10 match json with 11 | Jsont.Object (members, _) -> 12 List.find_map (fun ((name, _), value) -> 13 if name = key then Some value else None 14 ) members 15 | _ -> None 16 17let get_string json key = 18 match get_field json key with 19 | Some (Jsont.String (s, _)) -> Some s 20 | _ -> None 21 22let get_int json key = 23 match get_field json key with 24 | Some (Jsont.Number (f, _)) -> 25 let i = int_of_float f in 26 if float_of_int i = f then Some i else None 27 | _ -> None 28 29let get_bool json key = 30 match get_field json key with 31 | Some (Jsont.Bool (b, _)) -> Some b 32 | _ -> None 33 34let get_array json key = 35 match get_field json key with 36 | Some (Jsont.Array (items, _)) -> Some items 37 | _ -> None 38 39let as_string = function 40 | Jsont.String (s, _) -> Some s 41 | _ -> None