···5656(* For simple JSON encoding, we just take a Json.t value and encode it *)
5757let json (json_value : Json.t) =
5858 let content =
5959- try Json.to_string_exn ~format:Json.Minify Json.Codec.Value.t json_value
5959+ try Json.Value.to_string ~format:Json.Minify json_value
6060 with Json.Error e -> json_encoding_error e
6161 in
6262 String { content; mime = Mime.json }
···6464(* Typed JSON encoding using a Json.codec codec *)
6565let jsonv (type a) (codec : a Json.codec) (value : a) =
6666 let content =
6767- try Json.to_string_exn ~format:Json.Minify codec value
6767+ try Json.to_string ~format:Json.Minify codec value
6868 with Json.Error e -> json_encoding_error e
6969 in
7070 String { content; mime = Mime.json }
···8989let json_stream_source_create json_value =
9090 (* Encode the entire JSON value to string with minified format *)
9191 let content =
9292- try Json.to_string_exn ~format:Json.Minify Json.Codec.Value.t json_value
9292+ try Json.Value.to_string ~format:Json.Minify json_value
9393 with Json.Error e -> json_encoding_error e
9494 in
9595 let t = { Json_stream_source.content; offset = 0 } in
+2-2
lib/body.mli
···7575(** {1 Convenience Constructors} *)
76767777val json : Json.t -> t
7878-(** [json value] creates a JSON body from a Json.t value. The value
7979- is encoded to a JSON string with Content-Type: application/json.
7878+(** [json value] creates a JSON body from a Json.t value. The value is encoded
7979+ to a JSON string with Content-Type: application/json.
80808181 Example:
8282 {[
+1-1
lib/response.ml
···161161162162let json t =
163163 let body_str = text t in
164164- try Json.of_string_exn Json.Codec.Value.t body_str
164164+ try Json.Value.of_string_exn body_str
165165 with Json.Error e ->
166166 let preview =
167167 if String.length body_str > 200 then String.sub body_str 0 200
+3-3
test/test_huri.ml
···11111212let test_jsont_roundtrip_simple () =
1313 let uri = Uri.of_string "https://example.com" in
1414- let json_str = Json.to_string_exn ~format:Json.Minify Huri.jsont uri in
1414+ let json_str = Json.to_string ~format:Json.Minify Huri.jsont uri in
1515 let uri' = Json.of_string_exn Huri.jsont json_str in
1616 Alcotest.(check string) "roundtrip" (Uri.to_string uri) (Uri.to_string uri')
17171818let test_jsont_roundtrip_complex () =
1919 let uri = Uri.of_string "http://user:pass@host:8080/path?q=1#frag" in
2020- let json_str = Json.to_string_exn ~format:Json.Minify Huri.jsont uri in
2020+ let json_str = Json.to_string ~format:Json.Minify Huri.jsont uri in
2121 let uri' = Json.of_string_exn Huri.jsont json_str in
2222 Alcotest.(check string)
2323 "roundtrip complex" (Uri.to_string uri) (Uri.to_string uri')
24242525let test_jsont_encodes_as_string () =
2626 let uri = Uri.of_string "https://example.com" in
2727- let json_str = Json.to_string_exn ~format:Json.Minify Huri.jsont uri in
2727+ let json_str = Json.to_string ~format:Json.Minify Huri.jsont uri in
2828 Alcotest.(check bool)
2929 "starts with quote" true
3030 (String.length json_str > 0 && json_str.[0] = '"');