My own corner of monopam
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

ocaml-json: rename package jsont -> json

Directory ocaml-jsont -> ocaml-json. Library name jsont -> json,
jsont.bytesrw -> json.bytesrw, jsont.brr -> json.brr. Module renames:
Jsont -> Json, Jsont_base -> Json_base, Jsont_bytesrw -> Json_bytesrw,
Jsont_brr -> Json_brr. The internal type alias ['a jsont := 'a t] used
in sub-module signatures was renamed to ['a codec := 'a t] to avoid
clashing with the [json] value type now exposed at the top level.

+389 -351
+38
ocaml-json/json.opam
··· 1 + # This file is generated by dune, edit dune-project instead 2 + opam-version: "2.0" 3 + synopsis: "Declarative JSON data manipulation for OCaml" 4 + description: """ 5 + Json is a library for describing JSON data declaratively. Descriptions 6 + can be used to decode, encode, query, and update JSON values without 7 + constructing an intermediate representation. The bytesrw codec offers 8 + optional text-location tracking and layout preservation and is 9 + compatible with effect-based concurrency.""" 10 + maintainer: ["Thomas Gazagnaire <thomas@gazagnaire.org>"] 11 + authors: ["Daniel Bünzli"] 12 + license: "ISC" 13 + tags: ["org:blacksun" "codec" "json" "format"] 14 + homepage: "https://tangled.org/gazagnaire.org/ocaml-jsont" 15 + bug-reports: "https://tangled.org/gazagnaire.org/ocaml-jsont/issues" 16 + depends: [ 17 + "ocaml" {>= "4.14"} 18 + "dune" {>= "3.21" & >= "3.21"} 19 + "bytesrw" {>= "0.1.0"} 20 + "alcotest" {with-test} 21 + "odoc" {with-doc} 22 + ] 23 + build: [ 24 + ["dune" "subst"] {dev} 25 + [ 26 + "dune" 27 + "build" 28 + "-p" 29 + name 30 + "-j" 31 + jobs 32 + "@install" 33 + "@runtest" {with-test} 34 + "@doc" {with-doc} 35 + ] 36 + ] 37 + dev-repo: "git+https://tangled.org/gazagnaire.org/ocaml-jsont" 38 + x-maintenance-intent: ["(latest)"]
+6
ocaml-json/lib/brr/dune
··· 1 + (library 2 + (name json_brr) 3 + (public_name json.brr) 4 + (modules json_brr) 5 + (libraries json brr) 6 + (optional))
+5
ocaml-json/lib/bytesrw/dune
··· 1 + (library 2 + (name json_bytesrw) 3 + (public_name json.bytesrw) 4 + (modules json_bytesrw) 5 + (libraries json bytesrw))
+4
ocaml-json/lib/dune
··· 1 + (library 2 + (name json) 3 + (public_name json) 4 + (modules json json_base))
ocaml-jsont/CHANGES.md ocaml-json/CHANGES.md
ocaml-jsont/LICENSE.md ocaml-json/LICENSE.md
ocaml-jsont/README.md ocaml-json/README.md
+3 -3
ocaml-jsont/dune-project ocaml-json/dune-project
··· 1 1 (lang dune 3.21) 2 2 3 - (name jsont) 3 + (name json) 4 4 5 5 (generate_opam_files true) 6 6 ··· 10 10 (maintainers "Thomas Gazagnaire <thomas@gazagnaire.org>") 11 11 12 12 (package 13 - (name jsont) 13 + (name json) 14 14 (synopsis "Declarative JSON data manipulation for OCaml") 15 15 (tags (org:blacksun codec json format)) 16 16 (description 17 - "Jsont is a library for describing JSON data declaratively. Descriptions 17 + "Json is a library for describing JSON data declaratively. Descriptions 18 18 can be used to decode, encode, query, and update JSON values without 19 19 constructing an intermediate representation. The bytesrw codec offers 20 20 optional text-location tracking and layout preservation and is
-6
ocaml-jsont/lib/brr/dune
··· 1 - (library 2 - (name jsont_brr) 3 - (public_name jsont.brr) 4 - (modules jsont_brr) 5 - (libraries jsont brr) 6 - (optional))
+48 -48
ocaml-jsont/lib/brr/jsont_brr.ml ocaml-json/lib/brr/json_brr.ml
··· 3 3 SPDX-License-Identifier: ISC 4 4 ---------------------------------------------------------------------------*) 5 5 6 - open Jsont.Repr 6 + open Json.Repr 7 7 8 - (* Converting between Jsont.Error.t and Jv.Error.t values *) 8 + (* Converting between Json.Error.t and Jv.Error.t values *) 9 9 10 - let error_to_jv_error e = Jv.Error.v (Jstr.of_string (Jsont.Error.to_string e)) 10 + let error_to_jv_error e = Jv.Error.v (Jstr.of_string (Json.Error.to_string e)) 11 11 12 12 let jv_error_to_error e = 13 - let ctx = Jsont.Error.Context.empty and meta = Jsont.Meta.none in 14 - Jsont.Error.make_msg ctx meta (Jstr.to_string (Jv.Error.message e)) 13 + let ctx = Json.Error.Context.empty and meta = Json.Meta.none in 14 + Json.Error.make_msg ctx meta (Jstr.to_string (Jv.Error.message e)) 15 15 16 16 (* Browser JSON codec *) 17 17 ··· 22 22 let json_stringify ~format v = 23 23 let args = 24 24 match format with 25 - | Jsont.Minify -> [| v |] 26 - | Jsont.Indent | Jsont.Layout -> [| v; Jv.null; Jv.of_jstr indent |] 25 + | Json.Minify -> [| v |] 26 + | Json.Indent | Json.Layout -> [| v; Jv.null; Jv.of_jstr indent |] 27 27 in 28 28 Jv.to_jstr (Jv.call json "stringify" args) 29 29 ··· 36 36 let type_array = Jv.get Jv.global "Array" 37 37 38 38 let jv_sort jv = 39 - if Jv.is_null jv then Jsont.Sort.Null 39 + if Jv.is_null jv then Json.Sort.Null 40 40 else 41 41 let t = Jv.typeof jv in 42 - if Jstr.equal t type_bool then Jsont.Sort.Bool 43 - else if Jstr.equal t type_number then Jsont.Sort.Number 44 - else if Jstr.equal t type_string then Jsont.Sort.String 42 + if Jstr.equal t type_bool then Json.Sort.Bool 43 + else if Jstr.equal t type_number then Json.Sort.Number 44 + else if Jstr.equal t type_string then Json.Sort.String 45 45 else if Jstr.equal t type_object then 46 - if Jv.is_array jv then Jsont.Sort.Array else Jsont.Sort.Object 46 + if Jv.is_array jv then Json.Sort.Array else Json.Sort.Object 47 47 else 48 - Jsont.Error.msgf Jsont.Meta.none "Not a JSON value: %s" (Jstr.to_string t) 48 + Json.Error.msgf Json.Meta.none "Not a JSON value: %s" (Jstr.to_string t) 49 49 50 50 (* Getting the members of a Jv.t object in various ways *) 51 51 ··· 67 67 (* Decoding *) 68 68 69 69 let error_push_array map i e = 70 - Jsont.Repr.error_push_array Jsont.Meta.none map (i, Jsont.Meta.none) e 70 + Json.Repr.error_push_array Json.Meta.none map (i, Json.Meta.none) e 71 71 72 72 let error_push_object map n e = 73 - Jsont.Repr.error_push_object Jsont.Meta.none map (n, Jsont.Meta.none) e 73 + Json.Repr.error_push_object Json.Meta.none map (n, Json.Meta.none) e 74 74 75 - let type_error t ~fnd = Jsont.Repr.type_error Jsont.Meta.none t ~fnd 75 + let type_error t ~fnd = Json.Repr.type_error Json.Meta.none t ~fnd 76 76 77 77 let find_all_unexpected ~mem_decs mems = 78 78 let unexpected (n, _jname) = 79 79 match String_map.find_opt n mem_decs with 80 - | None -> Some (n, Jsont.Meta.none) 80 + | None -> Some (n, Json.Meta.none) 81 81 | Some _ -> None 82 82 in 83 83 List.filter_map unexpected mems 84 84 85 - let rec decode : type a. a Jsont.Repr.t -> Jv.t -> a = 85 + let rec decode : type a. a Json.Repr.t -> Jv.t -> a = 86 86 fun t jv -> 87 87 match t with 88 88 | Null map -> ( 89 89 match jv_sort jv with 90 - | Null -> map.dec Jsont.Meta.none () 90 + | Null -> map.dec Json.Meta.none () 91 91 | fnd -> type_error t ~fnd) 92 92 | Bool map -> ( 93 93 match jv_sort jv with 94 - | Bool -> map.dec Jsont.Meta.none (Jv.to_bool jv) 94 + | Bool -> map.dec Json.Meta.none (Jv.to_bool jv) 95 95 | fnd -> type_error t ~fnd) 96 96 | Number map -> ( 97 97 match jv_sort jv with 98 - | Number -> map.dec Jsont.Meta.none (Jv.to_float jv) 99 - | Null -> map.dec Jsont.Meta.none Float.nan 98 + | Number -> map.dec Json.Meta.none (Jv.to_float jv) 99 + | Null -> map.dec Json.Meta.none Float.nan 100 100 | fnd -> type_error t ~fnd) 101 101 | String map -> ( 102 102 match jv_sort jv with 103 - | String -> map.dec Jsont.Meta.none (Jv.to_string jv) 103 + | String -> map.dec Json.Meta.none (Jv.to_string jv) 104 104 | fnd -> type_error t ~fnd) 105 105 | Array map -> ( 106 106 match jv_sort jv with ··· 122 122 try 123 123 if map.dec_skip i !b then () 124 124 else b := map.dec_add i (decode map.elt (Jv.Jarray.get jv i)) !b 125 - with Jsont.Error e -> error_push_array map i e 125 + with Json.Error e -> error_push_array map i e 126 126 done; 127 - map.dec_finish Jsont.Meta.none len !b 127 + map.dec_finish Json.Meta.none len !b 128 128 129 129 and decode_object : type o. (o, o) object_map -> Jv.t -> o = 130 130 fun map jv -> ··· 151 151 | Object_cases (umems', cases) -> 152 152 let umems' = Unknown_mems umems' in 153 153 let umems, dict = 154 - Jsont.Repr.override_unknown_mems ~by:umems umems' dict 154 + Json.Repr.override_unknown_mems ~by:umems umems' dict 155 155 in 156 156 decode_object_cases map umems cases mem_decs dict names jv 157 157 | Object_basic umems' -> ( 158 158 let umems' = Unknown_mems (Some umems') in 159 159 let umems, dict = 160 - Jsont.Repr.override_unknown_mems ~by:umems umems' dict 160 + Json.Repr.override_unknown_mems ~by:umems umems' dict 161 161 in 162 162 match umems with 163 163 | Unknown_mems (Some Unknown_skip | None) -> ··· 185 185 fun map umems umap mem_decs dict names jv -> 186 186 match names with 187 187 | [] -> 188 - Jsont.Repr.finish_object_decode map Jsont.Meta.none umems umap mem_decs 188 + Json.Repr.finish_object_decode map Json.Meta.none umems umap mem_decs 189 189 dict 190 190 | (n, jname) :: names -> ( 191 191 match String_map.find_opt n mem_decs with 192 192 | Some (Mem_dec m) -> 193 193 let dict = 194 194 try Dict.add m.id (decode m.type' (Jv.get' jv jname)) dict 195 - with Jsont.Error e -> error_push_object map n e 195 + with Json.Error e -> error_push_object map n e 196 196 in 197 197 let mem_decs = String_map.remove n mem_decs in 198 198 decode_object_basic map umems umap mem_decs dict names jv ··· 202 202 decode_object_basic map umems umap mem_decs dict names jv 203 203 | Unknown_error -> 204 204 let fnd = 205 - (n, Jsont.Meta.none) :: find_all_unexpected ~mem_decs names 205 + (n, Json.Meta.none) :: find_all_unexpected ~mem_decs names 206 206 in 207 - Jsont.Repr.unexpected_mems_error Jsont.Meta.none map ~fnd 207 + Json.Repr.unexpected_mems_error Json.Meta.none map ~fnd 208 208 | Unknown_keep (mmap, _) -> 209 209 let umap = 210 210 let v = 211 211 try decode mmap.mems_type (Jv.get' jv jname) 212 - with Jsont.Error e -> error_push_object map n e 212 + with Json.Error e -> error_push_object map n e 213 213 in 214 - mmap.dec_add Jsont.Meta.none n v umap 214 + mmap.dec_add Json.Meta.none n v umap 215 215 in 216 216 decode_object_basic map umems umap mem_decs dict names jv)) 217 217 ··· 228 228 let decode_case_tag tag = 229 229 let eq_tag (Case c) = cases.tag_compare c.tag tag = 0 in 230 230 match List.find_opt eq_tag cases.cases with 231 - | None -> Jsont.Repr.unexpected_case_tag_error Jsont.Meta.none map cases tag 231 + | None -> Json.Repr.unexpected_case_tag_error Json.Meta.none map cases tag 232 232 | Some (Case case) -> 233 233 let mems = String_map.remove cases.tag.name names in 234 234 let dict = ··· 239 239 match String_map.find_opt cases.tag.name names with 240 240 | Some jname -> ( 241 241 try decode_case_tag (decode cases.tag.type' (Jv.get' jv jname)) 242 - with Jsont.Error e -> error_push_object map cases.tag.name e) 242 + with Json.Error e -> error_push_object map cases.tag.name e) 243 243 | None -> ( 244 244 match cases.tag.dec_absent with 245 245 | Some tag -> decode_case_tag tag 246 246 | None -> 247 247 let exp = String_map.singleton cases.tag.name (Mem_dec cases.tag) in 248 248 let fnd = jv_mem_name_list jv in 249 - Jsont.Repr.missing_mems_error Jsont.Meta.none map ~exp ~fnd) 249 + Json.Repr.missing_mems_error Json.Meta.none map ~exp ~fnd) 250 250 251 251 and decode_any : type a. a t -> a any_map -> Jv.t -> a = 252 252 fun t map jv -> ··· 261 261 | Array as s -> case t map.dec_array s jv 262 262 | Object as s -> case t map.dec_object s jv 263 263 264 - let decode t jv = decode (Jsont.Repr.of_t t) jv 265 - let decode_jv' t jv = try Ok (decode t jv) with Jsont.Error e -> Error e 264 + let decode t jv = decode (Json.Repr.of_t t) jv 265 + let decode_jv' t jv = try Ok (decode t jv) with Json.Error e -> Error e 266 266 let decode_jv t jv = Result.map_error error_to_jv_error (decode_jv' t jv) 267 267 268 268 let decode' t s = 269 269 try Ok (decode t (json_parse s)) with 270 270 | Jv.Error e -> Error (jv_error_to_error e) 271 - | Jsont.Error e -> Error e 271 + | Json.Error e -> Error e 272 272 273 273 let decode t json = Result.map_error error_to_jv_error (decode' t json) 274 274 ··· 288 288 try 289 289 Jv.Jarray.set a i (encode map.elt vi); 290 290 a 291 - with Jsont.Error e -> error_push_array map i e 291 + with Json.Error e -> error_push_array map i e 292 292 in 293 293 map.enc (add map) (Jv.Jarray.create 0) v 294 294 | Object map -> encode_object map ~do_unknown:true v (Jv.obj [||]) ··· 297 297 | Rec t -> encode (Lazy.force t) v 298 298 299 299 and encode_object : type o. 300 - (o, o) Jsont.Repr.object_map -> do_unknown:bool -> o -> Jv.t -> Jv.t = 300 + (o, o) Json.Repr.object_map -> do_unknown:bool -> o -> Jv.t -> Jv.t = 301 301 fun map ~do_unknown o jv -> 302 302 let encode_mem map o jv (Mem_enc mmap) = 303 303 try ··· 306 306 else ( 307 307 Jv.set' jv (Jstr.of_string mmap.name) (encode mmap.type' v); 308 308 jv) 309 - with Jsont.Error e -> error_push_object map mmap.name e 309 + with Json.Error e -> error_push_object map mmap.name e 310 310 in 311 311 let jv = List.fold_left (encode_mem map o) jv map.mem_encs in 312 312 match map.shape with ··· 322 322 let tag = encode cases.tag.type' case.tag in 323 323 Jv.set' jv (Jstr.of_string cases.tag.name) tag; 324 324 jv 325 - with Jsont.Error e -> error_push_object map cases.tag.name e 325 + with Json.Error e -> error_push_object map cases.tag.name e 326 326 in 327 327 match u with 328 328 | Some (Unknown_keep (umap, enc)) -> ··· 338 338 try 339 339 Jv.set' jv (Jstr.of_string name) (encode umap.mems_type v); 340 340 jv 341 - with Jsont.Error e -> error_push_object map name e 341 + with Json.Error e -> error_push_object map name e 342 342 in 343 343 umap.enc (encode_mem map) mems jv 344 344 345 - let encode t v = encode (Jsont.Repr.of_t t) v 346 - let encode_jv' t v = try Ok (encode t v) with Jsont.Error e -> Error e 345 + let encode t v = encode (Json.Repr.of_t t) v 346 + let encode_jv' t v = try Ok (encode t v) with Json.Error e -> Error e 347 347 let encode_jv t v = Result.map_error error_to_jv_error (encode_jv' t v) 348 348 349 - let encode' ?(format = Jsont.Minify) t v = 349 + let encode' ?(format = Json.Minify) t v = 350 350 try Ok (json_stringify ~format (encode t v)) with 351 351 | Jv.Error e -> Error (jv_error_to_error e) 352 - | Jsont.Error e -> Error e 352 + | Json.Error e -> Error e 353 353 354 354 let encode ?format t v = 355 355 Result.map_error error_to_jv_error (encode' ?format t v)
+16 -16
ocaml-jsont/lib/brr/jsont_brr.mli ocaml-json/lib/brr/json_brr.mli
··· 19 19 20 20 (** {1:decode Decode} *) 21 21 22 - val decode : 'a Jsont.t -> Jstr.t -> ('a, Jv.Error.t) result 22 + val decode : 'a Json.t -> Jstr.t -> ('a, Jv.Error.t) result 23 23 (** [decode t s] decodes the JSON data [s] according to [t]. *) 24 24 25 - val decode' : 'a Jsont.t -> Jstr.t -> ('a, Jsont.Error.t) result 25 + val decode' : 'a Json.t -> Jstr.t -> ('a, Json.Error.t) result 26 26 (** [decode' t s] is like {!val-decode} but preserves the error structure. *) 27 27 28 - val decode_jv : 'a Jsont.t -> Jv.t -> ('a, Jv.Error.t) result 28 + val decode_jv : 'a Json.t -> Jv.t -> ('a, Jv.Error.t) result 29 29 (** [decode_jv t v] decodes the JavaScript value [v] according to [t]. *) 30 30 31 - val decode_jv' : 'a Jsont.t -> Jv.t -> ('a, Jsont.Error.t) result 31 + val decode_jv' : 'a Json.t -> Jv.t -> ('a, Json.Error.t) result 32 32 (** [decode_jv'] is like {!decode_jv'} but preserves the error structure. *) 33 33 34 34 (** {1:encode Encode} *) 35 35 36 36 val encode : 37 - ?format:Jsont.format -> 'a Jsont.t -> 'a -> (Jstr.t, Jv.Error.t) result 37 + ?format:Json.format -> 'a Json.t -> 'a -> (Jstr.t, Jv.Error.t) result 38 38 (** [encode t v] encodes [v] to JSON according to [t]. [format] specifies how 39 - the JSON is formatted, defaults to {!Jsont.Minify}. The {!Jsont.Layout} 40 - format is unsupported, {!Jsont.Indent} is used instead. *) 39 + the JSON is formatted, defaults to {!Json.Minify}. The {!Json.Layout} 40 + format is unsupported, {!Json.Indent} is used instead. *) 41 41 42 42 val encode' : 43 - ?format:Jsont.format -> 'a Jsont.t -> 'a -> (Jstr.t, Jsont.Error.t) result 43 + ?format:Json.format -> 'a Json.t -> 'a -> (Jstr.t, Json.Error.t) result 44 44 (** [encode'] is like {!val-encode} but preserves the error structure. [format] 45 - specifies how the JSON is formatted, defaults to {!Jsont.Minify}. The 46 - {!Jsont.Layout} format is unsupported, {!Jsont.Indent} is used instead. *) 45 + specifies how the JSON is formatted, defaults to {!Json.Minify}. The 46 + {!Json.Layout} format is unsupported, {!Json.Indent} is used instead. *) 47 47 48 - val encode_jv : 'a Jsont.t -> 'a -> (Jv.t, Jv.Error.t) result 48 + val encode_jv : 'a Json.t -> 'a -> (Jv.t, Jv.Error.t) result 49 49 (** [encode_jv t v] encodes [v] to a JavaScript value according to [t]. *) 50 50 51 - val encode_jv' : 'a Jsont.t -> 'a -> (Jv.t, Jsont.Error.t) result 51 + val encode_jv' : 'a Json.t -> 'a -> (Jv.t, Json.Error.t) result 52 52 (** [encode_jv'] is like {!val-encode_jv} but preserves the error structure. *) 53 53 54 54 (** {1:recode Recode} *) 55 55 56 56 val recode : 57 - ?format:Jsont.format -> 'a Jsont.t -> Jstr.t -> (Jstr.t, Jv.Error.t) result 57 + ?format:Json.format -> 'a Json.t -> Jstr.t -> (Jstr.t, Jv.Error.t) result 58 58 (** [recode] is {!val-decode} followed by {!val-encode}. *) 59 59 60 60 val recode' : 61 - ?format:Jsont.format -> 'a Jsont.t -> Jstr.t -> (Jstr.t, Jsont.Error.t) result 61 + ?format:Json.format -> 'a Json.t -> Jstr.t -> (Jstr.t, Json.Error.t) result 62 62 (** [recode] is {!val-decode'} followed by {!val-encode'}. *) 63 63 64 - val recode_jv : 'a Jsont.t -> Jv.t -> (Jv.t, Jv.Error.t) result 64 + val recode_jv : 'a Json.t -> Jv.t -> (Jv.t, Jv.Error.t) result 65 65 (** [recode] is {!val-decode} followed by {!val-encode}. *) 66 66 67 - val recode_jv' : 'a Jsont.t -> Jv.t -> (Jv.t, Jsont.Error.t) result 67 + val recode_jv' : 'a Json.t -> Jv.t -> (Jv.t, Json.Error.t) result 68 68 (** [recode] is {!val-decode_jv'} followed by {!encode_jv'}. *)
-5
ocaml-jsont/lib/bytesrw/dune
··· 1 - (library 2 - (name jsont_bytesrw) 3 - (public_name jsont.bytesrw) 4 - (modules jsont_bytesrw) 5 - (libraries jsont bytesrw))
+129 -129
ocaml-jsont/lib/bytesrw/jsont_bytesrw.ml ocaml-json/lib/bytesrw/json_bytesrw.ml
··· 4 4 ---------------------------------------------------------------------------*) 5 5 6 6 open Bytesrw 7 - open Jsont.Repr 7 + open Json.Repr 8 8 9 9 (* XXX add these things to Stdlib.Uchar *) 10 10 ··· 40 40 41 41 let sot = 0x1A0000 (* start of text U+10FFFF + 1 *) 42 42 let eot = 0x1A0001 (* end of text U+10FFFF + 2 *) 43 - let pp_code = Jsont.Repr.pp_code 43 + let pp_code = Json.Repr.pp_code 44 44 45 45 let pp_quchar ppf u = 46 46 pp_code ppf ··· 59 59 60 60 type decoder = { 61 61 file : string; 62 - meta_none : Jsont.Meta.t; (* A meta with just [file] therein. *) 62 + meta_none : Json.Meta.t; (* A meta with just [file] therein. *) 63 63 locs : bool; (* [true] if text locations should be computed. *) 64 64 layout : bool; (* [true] if text layout should be kept. *) 65 65 reader : Bytes.Reader.t; (* The source of bytes. *) ··· 78 78 let make_decoder ?(locs = false) ?(layout = false) ?(file = "-") reader = 79 79 let overlap = Stdlib.Bytes.create uchar_max_utf_8_byte_length in 80 80 let token = Buffer.create 255 and ws = Buffer.create 255 in 81 - let meta_none = Jsont.Meta.make (Jsont.Textloc.(set_file none) file) in 81 + let meta_none = Json.Meta.make (Json.Textloc.(set_file none) file) in 82 82 { 83 83 file; 84 84 meta_none; ··· 113 113 let error_meta d = 114 114 let first_byte = get_last_byte d and first_line = get_line_pos d in 115 115 let last_byte = first_byte and last_line = first_line in 116 - Jsont.Meta.make 117 - @@ Jsont.Textloc.make ~file:d.file ~first_byte ~last_byte ~first_line 116 + Json.Meta.make 117 + @@ Json.Textloc.make ~file:d.file ~first_byte ~last_byte ~first_line 118 118 ~last_line 119 119 120 120 let error_meta_to_current ~first_byte ~first_line d = 121 121 let last_byte = get_last_byte d and last_line = get_line_pos d in 122 - Jsont.Meta.make 123 - @@ Jsont.Textloc.make ~file:d.file ~first_byte ~last_byte ~first_line 122 + Json.Meta.make 123 + @@ Json.Textloc.make ~file:d.file ~first_byte ~last_byte ~first_line 124 124 ~last_line 125 125 126 - let err_here d fmt = Jsont.Error.msgf (error_meta d) fmt 126 + let err_here d fmt = Json.Error.msgf (error_meta d) fmt 127 127 128 128 let err_to_here ~first_byte ~first_line d fmt = 129 - Jsont.Error.msgf (error_meta_to_current ~first_byte ~first_line d) fmt 129 + Json.Error.msgf (error_meta_to_current ~first_byte ~first_line d) fmt 130 130 131 131 let err_malformed_utf_8 d = 132 132 if d.i_next > d.i_max then ··· 142 142 143 143 let current_json_sort d = 144 144 match d.u with 145 - | 0x0066 (* f *) | 0x0074 (* t *) -> Jsont.Sort.Bool 146 - | 0x006E (* n *) -> Jsont.Sort.Null 147 - | 0x007B (* { *) -> Jsont.Sort.Object 148 - | 0x005B (* [ *) -> Jsont.Sort.Array 149 - | 0x0022 (* DQUOTE *) -> Jsont.Sort.String 150 - | u when is_number_start u -> Jsont.Sort.Number 145 + | 0x0066 (* f *) | 0x0074 (* t *) -> Json.Sort.Bool 146 + | 0x006E (* n *) -> Json.Sort.Null 147 + | 0x007B (* { *) -> Json.Sort.Object 148 + | 0x005B (* [ *) -> Json.Sort.Array 149 + | 0x0022 (* DQUOTE *) -> Json.Sort.String 150 + | u when is_number_start u -> Json.Sort.Number 151 151 | _ -> err_not_json_value d 152 152 153 153 let type_error d t = 154 - Jsont.Repr.type_error (error_meta d) t ~fnd:(current_json_sort d) 154 + Json.Repr.type_error (error_meta d) t ~fnd:(current_json_sort d) 155 155 156 156 (* Errors for constants *) 157 157 ··· 163 163 (* Errors for numbers *) 164 164 165 165 let err_float_parse meta tok = 166 - Jsont.Error.msgf meta "Could not parse %S to a %a" tok pp_code "float" 166 + Json.Error.msgf meta "Could not parse %S to a %a" tok pp_code "float" 167 167 168 168 let err_exp_digit d = 169 169 err_exp_while d pp_code "decimal digit" pp_code "number" pp_quchar d.u ··· 218 218 err_here d "Expected %a after %a but found %a" pp_code ":" pp_code 219 219 "member name" pp_quchar d.u 220 220 221 - let err_unclosed_object d (map : ('o, 'o) Jsont.Repr.object_map) = 222 - err_here d "Unclosed %a" Jsont.Repr.pp_kind 223 - (Jsont.Repr.object_map_kinded_sort map) 221 + let err_unclosed_object d (map : ('o, 'o) Json.Repr.object_map) = 222 + err_here d "Unclosed %a" Json.Repr.pp_kind 223 + (Json.Repr.object_map_kinded_sort map) 224 224 225 225 (* Decode next character in d.u *) 226 226 ··· 337 337 t 338 338 339 339 let textloc_to_current ~first_byte ~first_line d = 340 - if not d.locs then Jsont.Textloc.none 340 + if not d.locs then Json.Textloc.none 341 341 else 342 342 let last_byte = get_last_byte d and last_line = get_line_pos d in 343 - Jsont.Textloc.make ~file:d.file ~first_byte ~last_byte ~first_line 343 + Json.Textloc.make ~file:d.file ~first_byte ~last_byte ~first_line 344 344 ~last_line 345 345 346 346 let textloc_prev_ascii_char ~first_byte ~first_line d = 347 347 (* N.B. when we call that the line doesn't move and the char was on 348 348 a single byte *) 349 - if not d.locs then Jsont.Textloc.none 349 + if not d.locs then Json.Textloc.none 350 350 else 351 351 let last_byte = get_last_byte d and last_line = get_line_pos d in 352 352 let last_byte = last_byte - 1 in 353 - Jsont.Textloc.make ~file:d.file ~first_byte ~last_byte ~first_line 353 + Json.Textloc.make ~file:d.file ~first_byte ~last_byte ~first_line 354 354 ~last_line 355 355 356 356 let meta_make d ?ws_before ?ws_after textloc = 357 357 if (not d.locs) && not d.layout then d.meta_none 358 - else Jsont.Meta.make ?ws_before ?ws_after textloc 358 + else Json.Meta.make ?ws_before ?ws_after textloc 359 359 360 360 (* Decoding *) 361 361 ··· 607 607 let first_byte = get_last_byte d 608 608 and first_line = get_line_pos d in 609 609 try 610 - if map.dec_skip !i !b then decode d (of_t Jsont.ignore) 610 + if map.dec_skip !i !b then decode d (of_t Json.ignore) 611 611 else b := map.dec_add !i (decode d map.elt) !b 612 - with Jsont.Error e -> 612 + with Json.Error e -> 613 613 let imeta = error_meta_to_current ~first_byte ~first_line d in 614 - Jsont.Repr.error_push_array (error_meta d) map (!i, imeta) e 614 + Json.Repr.error_push_array (error_meta d) map (!i, imeta) e 615 615 end; 616 616 incr i; 617 617 match ··· 626 626 | fnd -> err_exp_comma_or_eoa d ~fnd 627 627 done; 628 628 (!b, !i) 629 - with Jsont.Error e -> 630 - Jsont.Error.adjust_context ~first_byte ~first_line e) 629 + with Json.Error e -> 630 + Json.Error.adjust_context ~first_byte ~first_line e) 631 631 in 632 632 let textloc = textloc_to_current d ~first_byte ~first_line in 633 633 let ws_after = ··· 649 649 decode_object_map d map (Unknown_mems None) String_map.empty 650 650 String_map.empty [] Dict.empty 651 651 with 652 - | Jsont.Error (ctx, meta, k) when Jsont.Error.Context.is_empty ctx -> 652 + | Json.Error (ctx, meta, k) when Json.Error.Context.is_empty ctx -> 653 653 let meta = 654 - (* This is for when Jsont.Repr.finish_object_decode raises. *) 655 - if Jsont.Textloc.is_none (Jsont.Meta.textloc meta) then 654 + (* This is for when Json.Repr.finish_object_decode raises. *) 655 + if Json.Textloc.is_none (Json.Meta.textloc meta) then 656 656 error_meta_to_current d ~first_byte ~first_line 657 657 else meta 658 658 in 659 - Jsont.Error.raise ctx meta k 660 - | Jsont.Error e -> Jsont.Error.adjust_context ~first_byte ~first_line e 659 + Json.Error.raise ctx meta k 660 + | Json.Error e -> Json.Error.adjust_context ~first_byte ~first_line e 661 661 in 662 662 let textloc = textloc_to_current d ~first_byte ~first_line in 663 663 let ws_after = ··· 666 666 ws_pop d 667 667 in 668 668 let meta = meta_make d ~ws_before ~ws_after textloc in 669 - let dict = Dict.add Jsont.Repr.object_meta_arg meta dict in 670 - Jsont.Repr.apply_dict map.dec dict 669 + let dict = Dict.add Json.Repr.object_meta_arg meta dict in 670 + Json.Repr.apply_dict map.dec dict 671 671 672 672 and decode_object_delayed : type o. 673 673 decoder -> 674 674 (o, o) object_map -> 675 675 mem_dec String_map.t -> 676 676 mem_dec String_map.t -> 677 - Jsont.object' -> 677 + Json.object' -> 678 678 Dict.t -> 679 - mem_dec String_map.t * Jsont.object' * Dict.t = 679 + mem_dec String_map.t * Json.object' * Dict.t = 680 680 fun d map mem_miss mem_decs delay dict -> 681 681 let rec loop d map mem_miss mem_decs rem_delay dict = function 682 682 | [] -> (mem_miss, rem_delay, dict) ··· 686 686 | Some (Mem_dec m) -> 687 687 let dict = 688 688 try 689 - let t = Jsont.Repr.unsafe_to_t m.type' in 689 + let t = Json.Repr.unsafe_to_t m.type' in 690 690 let v = 691 - match Jsont.Json.decode' t v with 691 + match Json.Json.decode' t v with 692 692 | Ok v -> v 693 - | Error e -> raise_notrace (Jsont.Error e) 693 + | Error e -> raise_notrace (Json.Error e) 694 694 in 695 695 Dict.add m.id v dict 696 - with Jsont.Error e -> 697 - Jsont.Repr.error_push_object (error_meta d) map nm e 696 + with Json.Error e -> 697 + Json.Repr.error_push_object (error_meta d) map nm e 698 698 in 699 699 let mem_miss = String_map.remove name mem_miss in 700 700 loop d map mem_miss mem_decs rem_delay dict delay) ··· 707 707 unknown_mems_option -> 708 708 mem_dec String_map.t -> 709 709 mem_dec String_map.t -> 710 - Jsont.object' -> 710 + Json.object' -> 711 711 Dict.t -> 712 712 Dict.t = 713 713 fun d map umems mem_miss mem_decs delay dict -> ··· 718 718 | Object_cases (umems', cases) -> 719 719 let umems' = Unknown_mems umems' in 720 720 let umems, dict = 721 - Jsont.Repr.override_unknown_mems ~by:umems umems' dict 721 + Json.Repr.override_unknown_mems ~by:umems umems' dict 722 722 in 723 723 decode_object_case d map umems cases mem_miss mem_decs delay dict 724 724 | Object_basic umems' -> ( ··· 727 727 in 728 728 let umems' = Unknown_mems (Some umems') in 729 729 let umems, dict = 730 - Jsont.Repr.override_unknown_mems ~by:umems umems' dict 730 + Json.Repr.override_unknown_mems ~by:umems umems' dict 731 731 in 732 732 match umems with 733 733 | Unknown_mems (Some Unknown_skip | None) -> ··· 737 737 decode_object_basic d map u () mem_miss mem_decs dict 738 738 else 739 739 let fnd = List.map fst delay in 740 - Jsont.Repr.unexpected_mems_error (error_meta d) map ~fnd 740 + Json.Repr.unexpected_mems_error (error_meta d) map ~fnd 741 741 | Unknown_mems (Some (Unknown_keep (umap, _) as u)) -> 742 742 let add_delay umems (((n, meta) as nm), v) = 743 743 try 744 - let t = Jsont.Repr.unsafe_to_t umap.mems_type in 744 + let t = Json.Repr.unsafe_to_t umap.mems_type in 745 745 let v = 746 - match Jsont.Json.decode' t v with 746 + match Json.Json.decode' t v with 747 747 | Ok v -> v 748 - | Error e -> raise_notrace (Jsont.Error e) 748 + | Error e -> raise_notrace (Json.Error e) 749 749 in 750 750 umap.dec_add meta n v umems 751 - with Jsont.Error e -> 752 - Jsont.Repr.error_push_object (error_meta d) map nm e 751 + with Json.Error e -> 752 + Json.Repr.error_push_object (error_meta d) map nm e 753 753 in 754 754 let umems = List.fold_left add_delay (umap.dec_empty ()) delay in 755 755 decode_object_basic d map u umems mem_miss mem_decs dict) ··· 770 770 d.meta_none 771 771 (* we add a correct one in decode_object *) 772 772 in 773 - Jsont.Repr.finish_object_decode map meta u umap mem_miss dict 773 + Json.Repr.finish_object_decode map meta u umap mem_miss dict 774 774 | 0x0022 -> 775 775 let meta = read_json_name d in 776 776 let name = token_pop d in ··· 779 779 let mem_miss = String_map.remove name mem_miss in 780 780 let dict = 781 781 try Dict.add mem.id (decode d mem.type') dict 782 - with Jsont.Error e -> 783 - Jsont.Repr.error_push_object (error_meta d) map (name, meta) e 782 + with Json.Error e -> 783 + Json.Repr.error_push_object (error_meta d) map (name, meta) e 784 784 in 785 785 read_json_mem_sep d; 786 786 decode_object_basic d map u umap mem_miss mem_decs dict ··· 788 788 match u with 789 789 | Unknown_skip -> 790 790 let () = 791 - try decode d (Jsont.Repr.of_t Jsont.ignore) 792 - with Jsont.Error e -> 793 - Jsont.Repr.error_push_object (error_meta d) map (name, meta) e 791 + try decode d (Json.Repr.of_t Json.ignore) 792 + with Json.Error e -> 793 + Json.Repr.error_push_object (error_meta d) map (name, meta) e 794 794 in 795 795 read_json_mem_sep d; 796 796 decode_object_basic d map u umap mem_miss mem_decs dict 797 797 | Unknown_error -> 798 798 let fnd = [ (name, meta) ] in 799 - Jsont.Repr.unexpected_mems_error (error_meta d) map ~fnd 799 + Json.Repr.unexpected_mems_error (error_meta d) map ~fnd 800 800 | Unknown_keep (umap', _) -> 801 801 let umap = 802 802 try umap'.dec_add meta name (decode d umap'.mems_type) umap 803 - with Jsont.Error e -> 804 - Jsont.Repr.error_push_object (error_meta d) map (name, meta) e 803 + with Json.Error e -> 804 + Json.Repr.error_push_object (error_meta d) map (name, meta) e 805 805 in 806 806 read_json_mem_sep d; 807 807 decode_object_basic d map u umap mem_miss mem_decs dict) ··· 816 816 (o, cases, tag) object_cases -> 817 817 mem_dec String_map.t -> 818 818 mem_dec String_map.t -> 819 - Jsont.object' -> 819 + Json.object' -> 820 820 Dict.t -> 821 821 Dict.t = 822 822 fun d map umems cases mem_miss mem_decs delay dict -> ··· 824 824 let eq_tag (Case c) = cases.tag_compare c.tag tag = 0 in 825 825 match List.find_opt eq_tag cases.cases with 826 826 | None -> ( 827 - try Jsont.Repr.unexpected_case_tag_error (error_meta d) map cases tag 828 - with Jsont.Error e -> 829 - Jsont.Repr.error_push_object (error_meta d) map 827 + try Json.Repr.unexpected_case_tag_error (error_meta d) map cases tag 828 + with Json.Error e -> 829 + Json.Repr.error_push_object (error_meta d) map 830 830 (cases.tag.name, nmeta) e) 831 831 | Some (Case case) -> 832 832 if sep then read_json_mem_sep d; ··· 844 844 | None -> 845 845 let fnd = List.map (fun ((n, _), _) -> n) delay in 846 846 let exp = String_map.singleton cases.tag.name (Mem_dec cases.tag) in 847 - Jsont.Repr.missing_mems_error (error_meta d) map ~exp ~fnd) 847 + Json.Repr.missing_mems_error (error_meta d) map ~exp ~fnd) 848 848 | 0x0022 -> 849 849 let meta = read_json_name d in 850 850 let name = token_pop d in 851 851 if String.equal name cases.tag.name then 852 852 let tag = 853 853 try decode d cases.tag.type' 854 - with Jsont.Error e -> 855 - Jsont.Repr.error_push_object (error_meta d) map (name, meta) e 854 + with Json.Error e -> 855 + Json.Repr.error_push_object (error_meta d) map (name, meta) e 856 856 in 857 857 decode_case_tag ~sep:true map umems cases mem_miss mem_decs meta tag 858 858 delay ··· 862 862 let mem_miss = String_map.remove name mem_miss in 863 863 let dict = 864 864 try Dict.add mem.id (decode d mem.type') dict 865 - with Jsont.Error e -> 866 - Jsont.Repr.error_push_object (error_meta d) map (name, meta) e 865 + with Json.Error e -> 866 + Json.Repr.error_push_object (error_meta d) map (name, meta) e 867 867 in 868 868 read_json_mem_sep d; 869 869 decode_object_case d map umems cases mem_miss mem_decs delay dict ··· 871 871 (* Because JSON can be out of order we don't know how to decode 872 872 this yet. Generic decode *) 873 873 let v = 874 - try decode d (Jsont.Repr.of_t Jsont.json) 875 - with Jsont.Error e -> 876 - Jsont.Repr.error_push_object (error_meta d) map (name, meta) e 874 + try decode d (Json.Repr.of_t Json.json) 875 + with Json.Error e -> 876 + Json.Repr.error_push_object (error_meta d) map (name, meta) e 877 877 in 878 878 let delay = ((name, meta), v) :: delay in 879 879 read_json_mem_sep d; ··· 901 901 let d = make_decoder ?layout ?locs ?file reader in 902 902 let v = 903 903 nextc d; 904 - decode d (Jsont.Repr.of_t t) 904 + decode d (Json.Repr.of_t t) 905 905 in 906 906 if d.u <> eot then err_exp_eot d else Ok v 907 - with Jsont.Error e -> Error e 907 + with Json.Error e -> Error e 908 908 909 909 let decode ?layout ?locs ?file t reader = 910 - Result.map_error Jsont.Error.to_string (decode' ?layout ?locs ?file t reader) 910 + Result.map_error Json.Error.to_string (decode' ?layout ?locs ?file t reader) 911 911 912 912 let decode_string' ?layout ?locs ?file t s = 913 913 decode' ?layout ?locs ?file t (Bytes.Reader.of_string s) ··· 922 922 o : Bytes.t; (* Buffer for slices. *) 923 923 o_max : int; (* Max index in [o]. *) 924 924 mutable o_next : int; (* Next writable index in [o]. *) 925 - format : Jsont.format; 925 + format : Json.format; 926 926 number_format : string; 927 927 } 928 928 929 - let make_encoder ?buf ?(format = Jsont.Minify) 930 - ?(number_format = Jsont.default_number_format) writer = 929 + let make_encoder ?buf ?(format = Json.Minify) 930 + ?(number_format = Json.default_number_format) writer = 931 931 let o = 932 932 match buf with 933 933 | Some buf -> buf ··· 975 975 write_char e ' ' 976 976 done 977 977 978 - let write_ws_before e m = write_bytes e (Jsont.Meta.ws_before m) 979 - let write_ws_after e m = write_bytes e (Jsont.Meta.ws_after m) 978 + let write_ws_before e m = write_bytes e (Json.Meta.ws_before m) 979 + let write_ws_after e m = write_bytes e (Json.Meta.ws_after m) 980 980 let write_json_null e = write_bytes e "null" 981 981 let write_json_bool e b = write_bytes e (if b then "true" else "false") 982 982 ··· 1031 1031 loop 0 0 (len - 1); 1032 1032 write_char e '"' 1033 1033 1034 - let encode_null (map : ('a, 'b) Jsont.Repr.base_map) e v = 1034 + let encode_null (map : ('a, 'b) Json.Repr.base_map) e v = 1035 1035 let () = map.enc v in 1036 1036 match e.format with 1037 - | Jsont.Minify | Jsont.Indent -> write_json_null e 1038 - | Jsont.Layout -> 1037 + | Json.Minify | Json.Indent -> write_json_null e 1038 + | Json.Layout -> 1039 1039 let meta = map.enc_meta v in 1040 1040 write_ws_before e meta; 1041 1041 write_json_null e; 1042 1042 write_ws_after e meta 1043 1043 1044 - let encode_bool (map : ('a, 'b) Jsont.Repr.base_map) e v = 1044 + let encode_bool (map : ('a, 'b) Json.Repr.base_map) e v = 1045 1045 let b = map.enc v in 1046 1046 match e.format with 1047 - | Jsont.Minify | Jsont.Indent -> write_json_bool e b 1048 - | Jsont.Layout -> 1047 + | Json.Minify | Json.Indent -> write_json_bool e b 1048 + | Json.Layout -> 1049 1049 let meta = map.enc_meta v in 1050 1050 write_ws_before e meta; 1051 1051 write_json_bool e b; 1052 1052 write_ws_after e meta 1053 1053 1054 - let encode_number (map : ('a, 'b) Jsont.Repr.base_map) e v = 1054 + let encode_number (map : ('a, 'b) Json.Repr.base_map) e v = 1055 1055 let n = map.enc v in 1056 1056 match e.format with 1057 - | Jsont.Minify | Jsont.Indent -> write_json_number e n 1058 - | Jsont.Layout -> 1057 + | Json.Minify | Json.Indent -> write_json_number e n 1058 + | Json.Layout -> 1059 1059 let meta = map.enc_meta v in 1060 1060 write_ws_before e meta; 1061 1061 write_json_number e n; 1062 1062 write_ws_after e meta 1063 1063 1064 - let encode_string (map : ('a, 'b) Jsont.Repr.base_map) e v = 1064 + let encode_string (map : ('a, 'b) Json.Repr.base_map) e v = 1065 1065 let s = map.enc v in 1066 1066 match e.format with 1067 - | Jsont.Minify | Jsont.Indent -> write_json_string e s 1068 - | Jsont.Layout -> 1067 + | Json.Minify | Json.Indent -> write_json_string e s 1068 + | Json.Layout -> 1069 1069 let meta = map.enc_meta v in 1070 1070 write_ws_before e meta; 1071 1071 write_json_string e s; ··· 1077 1077 1078 1078 let encode_mem_name e meta n = 1079 1079 match e.format with 1080 - | Jsont.Minify -> 1080 + | Json.Minify -> 1081 1081 write_json_string e n; 1082 1082 write_char e ':' 1083 - | Jsont.Indent -> 1083 + | Json.Indent -> 1084 1084 write_json_string e n; 1085 1085 write_bytes e ": " 1086 - | Jsont.Layout -> 1086 + | Json.Layout -> 1087 1087 write_ws_before e meta; 1088 1088 write_json_string e n; 1089 1089 write_ws_after e meta; 1090 1090 write_char e ':' 1091 1091 1092 - let rec encode : type a. nest:int -> a Jsont.Repr.t -> encoder -> a -> unit = 1092 + let rec encode : type a. nest:int -> a Json.Repr.t -> encoder -> a -> unit = 1093 1093 fun ~nest t e v -> 1094 1094 match t with 1095 1095 | Null map -> encode_null map e v ··· 1103 1103 | Rec t -> encode ~nest (Lazy.force t) e v 1104 1104 1105 1105 and encode_array : type a elt b. 1106 - nest:int -> (a, elt, b) Jsont.Repr.array_map -> encoder -> a -> unit = 1106 + nest:int -> (a, elt, b) Json.Repr.array_map -> encoder -> a -> unit = 1107 1107 fun ~nest map e v -> 1108 1108 let encode_element ~nest map e i v = 1109 1109 if i <> 0 then write_sep e; 1110 1110 try 1111 1111 encode ~nest map.elt e v; 1112 1112 e 1113 - with Jsont.Error e -> 1114 - Jsont.Repr.error_push_array Jsont.Meta.none map (i, Jsont.Meta.none) e 1113 + with Json.Error e -> 1114 + Json.Repr.error_push_array Json.Meta.none map (i, Json.Meta.none) e 1115 1115 in 1116 1116 match e.format with 1117 - | Jsont.Minify -> 1117 + | Json.Minify -> 1118 1118 write_char e '['; 1119 1119 ignore (map.enc (encode_element ~nest:(nest + 1) map) e v); 1120 1120 write_char e ']' 1121 - | Jsont.Layout -> 1121 + | Json.Layout -> 1122 1122 let meta = map.enc_meta v in 1123 1123 write_ws_before e meta; 1124 1124 write_char e '['; 1125 1125 ignore (map.enc (encode_element ~nest:(nest + 1) map) e v); 1126 1126 write_char e ']'; 1127 1127 write_ws_after e meta 1128 - | Jsont.Indent -> 1128 + | Json.Indent -> 1129 1129 let encode_element ~nest map e i v = 1130 1130 if i <> 0 then write_sep e; 1131 1131 write_char e '\n'; ··· 1133 1133 try 1134 1134 encode ~nest map.elt e v; 1135 1135 e 1136 - with Jsont.Error e -> 1137 - Jsont.Repr.error_push_array Jsont.Meta.none map (i, Jsont.Meta.none) e 1136 + with Json.Error e -> 1137 + Json.Repr.error_push_array Json.Meta.none map (i, Json.Meta.none) e 1138 1138 in 1139 1139 let array_not_empty e = 1140 1140 e.o_next = 0 || not (Bytes.get e.o (e.o_next - 1) = '[') ··· 1147 1147 write_char e ']' 1148 1148 1149 1149 and encode_object : type o enc. 1150 - nest:int -> (o, o) Jsont.Repr.object_map -> encoder -> o -> unit = 1150 + nest:int -> (o, o) Json.Repr.object_map -> encoder -> o -> unit = 1151 1151 fun ~nest map e o -> 1152 1152 match e.format with 1153 - | Jsont.Minify -> 1153 + | Json.Minify -> 1154 1154 write_char e '{'; 1155 1155 ignore 1156 1156 @@ encode_object_map ~nest:(nest + 1) map ~do_unknown:true e ~start:true o; 1157 1157 write_char e '}' 1158 - | Jsont.Layout -> 1158 + | Json.Layout -> 1159 1159 let meta = map.enc_meta o in 1160 1160 write_ws_before e meta; 1161 1161 write_char e '{'; ··· 1163 1163 @@ encode_object_map ~nest:(nest + 1) map ~do_unknown:true e ~start:true o; 1164 1164 write_char e '}'; 1165 1165 write_ws_after e meta 1166 - | Jsont.Indent -> 1166 + | Json.Indent -> 1167 1167 write_char e '{'; 1168 1168 let start = 1169 1169 encode_object_map ~nest:(nest + 1) map ~do_unknown:true e ~start:true o ··· 1175 1175 1176 1176 and encode_object_map : type o enc. 1177 1177 nest:int -> 1178 - (o, o) Jsont.Repr.object_map -> 1178 + (o, o) Json.Repr.object_map -> 1179 1179 do_unknown:bool -> 1180 1180 encoder -> 1181 1181 start:bool -> ··· 1188 1188 if mmap.enc_omit v then start 1189 1189 else begin 1190 1190 if not start then write_char e ','; 1191 - if e.format = Jsont.Indent then encode_mem_indent ~nest e; 1191 + if e.format = Json.Indent then encode_mem_indent ~nest e; 1192 1192 let meta = 1193 - (* if e.format = Jsont.Layout then mmap.enc_name_meta v else *) 1194 - Jsont.Meta.none 1193 + (* if e.format = Json.Layout then mmap.enc_name_meta v else *) 1194 + Json.Meta.none 1195 1195 in 1196 1196 encode_mem_name e meta mmap.name; 1197 1197 encode ~nest mmap.type' e v; 1198 1198 false 1199 1199 end 1200 - with Jsont.Error e -> 1201 - Jsont.Repr.error_push_object Jsont.Meta.none map 1202 - (mmap.name, Jsont.Meta.none) 1200 + with Json.Error e -> 1201 + Json.Repr.error_push_object Json.Meta.none map 1202 + (mmap.name, Json.Meta.none) 1203 1203 e 1204 1204 in 1205 1205 match map.shape with ··· 1241 1241 let encode_unknown_mem ~nest map umap e meta n v start = 1242 1242 try 1243 1243 if not start then write_char e ','; 1244 - if e.format = Jsont.Indent then encode_mem_indent ~nest e; 1244 + if e.format = Json.Indent then encode_mem_indent ~nest e; 1245 1245 encode_mem_name e meta n; 1246 1246 encode ~nest umap.mems_type e v; 1247 1247 false 1248 - with Jsont.Error e -> 1249 - Jsont.Repr.error_push_object Jsont.Meta.none map (n, Jsont.Meta.none) e 1248 + with Json.Error e -> 1249 + Json.Repr.error_push_object Json.Meta.none map (n, Json.Meta.none) e 1250 1250 in 1251 1251 umap.enc (encode_unknown_mem ~nest map umap e) mems start 1252 1252 1253 1253 let encode' ?buf ?format ?number_format t v ~eod w = 1254 1254 let e = make_encoder ?buf ?format ?number_format w in 1255 - let t = Jsont.Repr.of_t t in 1255 + let t = Json.Repr.of_t t in 1256 1256 try 1257 1257 Ok 1258 1258 (encode ~nest:0 t e v; 1259 1259 write_eot ~eod e) 1260 - with Jsont.Error e -> Error e 1260 + with Json.Error e -> Error e 1261 1261 1262 1262 let encode ?buf ?format ?number_format t v ~eod w = 1263 - Result.map_error Jsont.Error.to_string 1263 + Result.map_error Json.Error.to_string 1264 1264 @@ encode' ?buf ?format ?number_format ~eod t v w 1265 1265 1266 1266 let encode_string' ?buf ?format ?number_format t v = ··· 1271 1271 | Error _ as e -> e 1272 1272 1273 1273 let encode_string ?buf ?format ?number_format t v = 1274 - Result.map_error Jsont.Error.to_string 1274 + Result.map_error Json.Error.to_string 1275 1275 @@ encode_string' ?buf ?format ?number_format t v 1276 1276 1277 1277 (* Recode *) 1278 1278 1279 1279 let unsurprising_defaults layout format = 1280 1280 match (layout, format) with 1281 - | Some true, None -> (Some true, Some Jsont.Layout) 1282 - | None, (Some Jsont.Layout as l) -> (Some true, l) 1281 + | Some true, None -> (Some true, Some Json.Layout) 1282 + | None, (Some Json.Layout as l) -> (Some true, l) 1283 1283 | l, f -> (l, f) 1284 1284 1285 1285 let recode' ?layout ?locs ?file ?buf ?format ?number_format t r w ~eod = ··· 1289 1289 | Ok v -> encode' ?buf ?format ?number_format t v ~eod w 1290 1290 1291 1291 let recode ?layout ?locs ?file ?buf ?format ?number_format t r w ~eod = 1292 - Result.map_error Jsont.Error.to_string 1292 + Result.map_error Json.Error.to_string 1293 1293 @@ recode' ?layout ?locs ?file ?buf ?format ?number_format t r w ~eod 1294 1294 1295 1295 let recode_string' ?layout ?locs ?file ?buf ?format ?number_format t s = ··· 1299 1299 | Ok v -> encode_string' ?buf ?format ?number_format t v 1300 1300 1301 1301 let recode_string ?layout ?locs ?file ?buf ?format ?number_format t s = 1302 - Result.map_error Jsont.Error.to_string 1302 + Result.map_error Json.Error.to_string 1303 1303 @@ recode_string' ?layout ?locs ?file ?buf ?format ?number_format t s
+49 -49
ocaml-jsont/lib/bytesrw/jsont_bytesrw.mli ocaml-json/lib/bytesrw/json_bytesrw.mli
··· 21 21 val decode : 22 22 ?layout:bool -> 23 23 ?locs:bool -> 24 - ?file:Jsont.Textloc.fpath -> 25 - 'a Jsont.t -> 24 + ?file:Json.Textloc.fpath -> 25 + 'a Json.t -> 26 26 Bytes.Reader.t -> 27 27 ('a, string) result 28 28 (** [decode t r] decodes a value from [r] according to [t]. 29 - - If [layout] is [true] whitespace is preserved in {!Jsont.Meta.t} values. 29 + - If [layout] is [true] whitespace is preserved in {!Json.Meta.t} values. 30 30 Defaults to [false]. 31 - - If [locs] is [true] locations are preserved in {!Jsont.Meta.t} values and 31 + - If [locs] is [true] locations are preserved in {!Json.Meta.t} values and 32 32 error messages are precisely located. Defaults to [false]. 33 33 - [file] is the file path from which [r] is assumed to read. Defaults to 34 - {!Jsont.Textloc.file_none} *) 34 + {!Json.Textloc.file_none} *) 35 35 36 36 val decode' : 37 37 ?layout:bool -> 38 38 ?locs:bool -> 39 - ?file:Jsont.Textloc.fpath -> 40 - 'a Jsont.t -> 39 + ?file:Json.Textloc.fpath -> 40 + 'a Json.t -> 41 41 Bytes.Reader.t -> 42 - ('a, Jsont.Error.t) result 42 + ('a, Json.Error.t) result 43 43 (** [decode'] is like {!val-decode} but preserves the error structure. *) 44 44 45 45 val decode_string : 46 46 ?layout:bool -> 47 47 ?locs:bool -> 48 - ?file:Jsont.Textloc.fpath -> 49 - 'a Jsont.t -> 48 + ?file:Json.Textloc.fpath -> 49 + 'a Json.t -> 50 50 string -> 51 51 ('a, string) result 52 52 (** [decode_string] is like {!val-decode} but decodes directly from a string. *) ··· 54 54 val decode_string' : 55 55 ?layout:bool -> 56 56 ?locs:bool -> 57 - ?file:Jsont.Textloc.fpath -> 58 - 'a Jsont.t -> 57 + ?file:Json.Textloc.fpath -> 58 + 'a Json.t -> 59 59 string -> 60 - ('a, Jsont.Error.t) result 60 + ('a, Json.Error.t) result 61 61 (** [decode_string'] is like {!val-decode'} but decodes directly from a string. 62 62 *) 63 63 ··· 65 65 66 66 val encode : 67 67 ?buf:Bytes.t -> 68 - ?format:Jsont.format -> 69 - ?number_format:Jsont.number_format -> 70 - 'a Jsont.t -> 68 + ?format:Json.format -> 69 + ?number_format:Json.number_format -> 70 + 'a Json.t -> 71 71 'a -> 72 72 eod:bool -> 73 73 Bytes.Writer.t -> ··· 76 76 - If [buf] is specified it is used as a buffer for the slices written on 77 77 [w]. Defaults to a buffer of length {!Bytes.Writer.slice_length}[ w]. 78 78 - [format] specifies how the JSON should be formatted. Defaults to 79 - {!Jsont.Minify}. 79 + {!Json.Minify}. 80 80 - [number_format] specifies the format string to format numbers. Defaults to 81 - {!Jsont.default_number_format}. 81 + {!Json.default_number_format}. 82 82 - [eod] indicates whether {!Bytesrw.Bytes.Slice.eod} should be written on 83 83 [w]. *) 84 84 85 85 val encode' : 86 86 ?buf:Bytes.t -> 87 - ?format:Jsont.format -> 88 - ?number_format:Jsont.number_format -> 89 - 'a Jsont.t -> 87 + ?format:Json.format -> 88 + ?number_format:Json.number_format -> 89 + 'a Json.t -> 90 90 'a -> 91 91 eod:bool -> 92 92 Bytes.Writer.t -> 93 - (unit, Jsont.Error.t) result 93 + (unit, Json.Error.t) result 94 94 (** [encode'] is like {!val-encode} but preserves the error structure. *) 95 95 96 96 val encode_string : 97 97 ?buf:Bytes.t -> 98 - ?format:Jsont.format -> 99 - ?number_format:Jsont.number_format -> 100 - 'a Jsont.t -> 98 + ?format:Json.format -> 99 + ?number_format:Json.number_format -> 100 + 'a Json.t -> 101 101 'a -> 102 102 (string, string) result 103 103 (** [encode_string] is like {!val-encode} but writes to a string. *) 104 104 105 105 val encode_string' : 106 106 ?buf:Bytes.t -> 107 - ?format:Jsont.format -> 108 - ?number_format:Jsont.number_format -> 109 - 'a Jsont.t -> 107 + ?format:Json.format -> 108 + ?number_format:Json.number_format -> 109 + 'a Json.t -> 110 110 'a -> 111 - (string, Jsont.Error.t) result 111 + (string, Json.Error.t) result 112 112 (** [encode_string'] is like {!val-encode'} but writes to a string. *) 113 113 114 114 (** {1:recode Recode} 115 115 116 116 The defaults in these functions are those of {!val-decode} and 117 117 {!val-encode}, except if [layout] is [true], [format] defaults to 118 - [Jsont.Layout] and vice-versa. *) 118 + [Json.Layout] and vice-versa. *) 119 119 120 120 val recode : 121 121 ?layout:bool -> 122 122 ?locs:bool -> 123 - ?file:Jsont.Textloc.fpath -> 123 + ?file:Json.Textloc.fpath -> 124 124 ?buf:Bytes.t -> 125 - ?format:Jsont.format -> 126 - ?number_format:Jsont.number_format -> 127 - 'a Jsont.t -> 125 + ?format:Json.format -> 126 + ?number_format:Json.number_format -> 127 + 'a Json.t -> 128 128 Bytes.Reader.t -> 129 129 Bytes.Writer.t -> 130 130 eod:bool -> ··· 134 134 val recode' : 135 135 ?layout:bool -> 136 136 ?locs:bool -> 137 - ?file:Jsont.Textloc.fpath -> 137 + ?file:Json.Textloc.fpath -> 138 138 ?buf:Bytes.t -> 139 - ?format:Jsont.format -> 140 - ?number_format:Jsont.number_format -> 141 - 'a Jsont.t -> 139 + ?format:Json.format -> 140 + ?number_format:Json.number_format -> 141 + 'a Json.t -> 142 142 Bytes.Reader.t -> 143 143 Bytes.Writer.t -> 144 144 eod:bool -> 145 - (unit, Jsont.Error.t) result 145 + (unit, Json.Error.t) result 146 146 (** [recode'] is like {!val-recode} but preserves the error structure. *) 147 147 148 148 val recode_string : 149 149 ?layout:bool -> 150 150 ?locs:bool -> 151 - ?file:Jsont.Textloc.fpath -> 151 + ?file:Json.Textloc.fpath -> 152 152 ?buf:Bytes.t -> 153 - ?format:Jsont.format -> 154 - ?number_format:Jsont.number_format -> 155 - 'a Jsont.t -> 153 + ?format:Json.format -> 154 + ?number_format:Json.number_format -> 155 + 'a Json.t -> 156 156 string -> 157 157 (string, string) result 158 158 (** [recode] is {!decode_string} followed by {!recode_string}. *) ··· 160 160 val recode_string' : 161 161 ?layout:bool -> 162 162 ?locs:bool -> 163 - ?file:Jsont.Textloc.fpath -> 163 + ?file:Json.Textloc.fpath -> 164 164 ?buf:Bytes.t -> 165 - ?format:Jsont.format -> 166 - ?number_format:Jsont.number_format -> 167 - 'a Jsont.t -> 165 + ?format:Json.format -> 166 + ?number_format:Json.number_format -> 167 + 'a Json.t -> 168 168 string -> 169 - (string, Jsont.Error.t) result 169 + (string, Json.Error.t) result 170 170 (** [recode_string'] is like {!val-recode_string} but preserves the error 171 171 structure. *) 172 172 ··· 185 185 {{:https://262.ecma-international.org/6.0/#sec-internalizejsonproperty} 186 186 [JSON.parse]} and the last one takes over, however duplicate members all 187 187 have to parse with the specified type as we error as soon as possible. Also 188 - {{!Jsont.Object.case_mem}case members} are not allowed to duplicate. *) 188 + {{!Json.Object.case_mem}case members} are not allowed to duplicate. *)
-4
ocaml-jsont/lib/dune
··· 1 - (library 2 - (name jsont) 3 - (public_name jsont) 4 - (modules jsont jsont_base))
+37 -37
ocaml-jsont/lib/jsont.ml ocaml-json/lib/json.ml
··· 3 3 SPDX-License-Identifier: ISC 4 4 ---------------------------------------------------------------------------*) 5 5 6 - module Fmt = Jsont_base.Fmt 6 + module Fmt = Json_base.Fmt 7 7 8 8 type 'a fmt = 'a Fmt.t 9 9 ··· 12 12 let pp_name = Fmt.code 13 13 let pp_int ppf i = Fmt.code ppf (Int.to_string i) 14 14 15 - module Textloc = Jsont_base.Textloc 16 - module Meta = Jsont_base.Meta 15 + module Textloc = Json_base.Textloc 16 + module Meta = Json_base.Meta 17 17 18 18 type 'a node = 'a * Meta.t 19 19 20 - module Path = Jsont_base.Path 21 - module Sort = Jsont_base.Sort 20 + module Path = Json_base.Path 21 + module Sort = Json_base.Sort 22 22 23 23 type error_kind = string 24 24 type context_index = string node * Path.index ··· 172 172 module Repr = struct 173 173 (* See the .mli for documentation *) 174 174 module String_map = Map.Make (String) 175 - module Type = Jsont_base.Type 175 + module Type = Json_base.Type 176 176 177 177 type ('ret, 'f) dec_fun = 178 178 | Dec_fun : 'f -> ('ret, 'f) dec_fun ··· 736 736 let kind = "uint8" in 737 737 let dec meta v = 738 738 check_finite_number meta ~kind v; 739 - if Jsont_base.Number.in_exact_uint8_range v then Int.of_float v 739 + if Json_base.Number.in_exact_uint8_range v then Int.of_float v 740 740 else Error.number_range meta ~kind v 741 741 in 742 742 let enc v = 743 - if Jsont_base.Number.int_is_uint8 v then Int.to_float v 743 + if Json_base.Number.int_is_uint8 v then Int.to_float v 744 744 else Error.integer_range Meta.none ~kind v 745 745 in 746 746 Base.number (Base.map ~kind ~dec ~enc ()) ··· 749 749 let kind = "uint16" in 750 750 let dec meta v = 751 751 check_finite_number meta ~kind v; 752 - if Jsont_base.Number.in_exact_uint16_range v then Int.of_float v 752 + if Json_base.Number.in_exact_uint16_range v then Int.of_float v 753 753 else Error.number_range meta ~kind v 754 754 in 755 755 let enc v = 756 - if Jsont_base.Number.int_is_uint16 v then Int.to_float v 756 + if Json_base.Number.int_is_uint16 v then Int.to_float v 757 757 else Error.integer_range Meta.none ~kind v 758 758 in 759 759 Base.number (Base.map ~kind ~dec ~enc ()) ··· 762 762 let kind = "int8" in 763 763 let dec meta v = 764 764 check_finite_number meta ~kind v; 765 - if Jsont_base.Number.in_exact_int8_range v then Int.of_float v 765 + if Json_base.Number.in_exact_int8_range v then Int.of_float v 766 766 else Error.number_range meta ~kind v 767 767 in 768 768 let enc v = 769 - if Jsont_base.Number.int_is_int8 v then Int.to_float v 769 + if Json_base.Number.int_is_int8 v then Int.to_float v 770 770 else Error.integer_range Meta.none ~kind v 771 771 in 772 772 Base.number (Base.map ~kind ~dec ~enc ()) ··· 775 775 let kind = "int16" in 776 776 let dec meta v = 777 777 check_finite_number meta ~kind v; 778 - if Jsont_base.Number.in_exact_int16_range v then Int.of_float v 778 + if Json_base.Number.in_exact_int16_range v then Int.of_float v 779 779 else Error.number_range meta ~kind v 780 780 in 781 781 let enc v = 782 - if Jsont_base.Number.int_is_int16 v then Int.to_float v 782 + if Json_base.Number.int_is_int16 v then Int.to_float v 783 783 else Error.integer_range Meta.none ~kind v 784 784 in 785 785 Base.number (Base.map ~kind ~dec ~enc ()) ··· 788 788 let kind = "int32" in 789 789 let dec meta v = 790 790 check_finite_number meta ~kind v; 791 - if Jsont_base.Number.in_exact_int32_range v then Int32.of_float v 791 + if Json_base.Number.in_exact_int32_range v then Int32.of_float v 792 792 else Error.number_range meta ~kind v 793 793 in 794 794 let enc = ··· 811 811 range on encoding. *) 812 812 let kind = "int64" in 813 813 let dec meta v = 814 - if Jsont_base.Number.in_exact_int64_range v then Int64.of_float v 814 + if Json_base.Number.in_exact_int64_range v then Int64.of_float v 815 815 else Error.number_range meta ~kind v 816 816 in 817 817 Base.number (Base.map ~kind ~dec ~enc:Int64.to_float ()) ··· 819 819 let int64 = 820 820 let dec_number = int64_number and dec_string = int64_as_string in 821 821 let enc v = 822 - if Jsont_base.Number.can_store_exact_int64 v then int64_number 822 + if Json_base.Number.can_store_exact_int64 v then int64_number 823 823 else int64_as_string 824 824 in 825 825 any ~kind:"int64" ~dec_number ~dec_string ~enc () ··· 838 838 encoding. *) 839 839 let kind = "OCaml int" in 840 840 let dec meta v = 841 - if Jsont_base.Number.in_exact_int_range v then Int.of_float v 841 + if Json_base.Number.in_exact_int_range v then Int.of_float v 842 842 else Error.number_range meta ~kind v 843 843 in 844 844 Base.number (Base.map ~kind ~dec ~enc:Int.to_float ()) 845 845 846 846 let int = 847 847 let enc v = 848 - if Jsont_base.Number.can_store_exact_int v then int_number 848 + if Json_base.Number.can_store_exact_int v then int_number 849 849 else int_as_string 850 850 in 851 851 let dec_number = int_number and dec_string = int_as_string in ··· 896 896 let binary_string = 897 897 let kind = "hex" in 898 898 let kind' = Sort.kinded ~kind String in 899 - let dec = Base.dec_result ~kind:kind' Jsont_base.binary_string_of_hex in 900 - let enc = Base.enc Jsont_base.binary_string_to_hex in 899 + let dec = Base.dec_result ~kind:kind' Json_base.binary_string_of_hex in 900 + let enc = Base.enc Json_base.binary_string_to_hex in 901 901 Base.string (Base.map ~kind ~dec ~enc ()) 902 902 903 903 (* Arrays and tuples *) ··· 961 961 let enc = { enc = list_enc } in 962 962 map ?kind ?doc ~dec_empty ?dec_skip ~dec_add ~dec_finish ~enc elt 963 963 964 - type 'a array_builder = 'a Jsont_base.Rarray.t 964 + type 'a array_builder = 'a Json_base.Rarray.t 965 965 966 966 let array_enc f acc a = 967 967 let acc = ref acc in ··· 971 971 !acc 972 972 973 973 let array_map ?kind ?doc ?dec_skip elt = 974 - let dec_empty () = Jsont_base.Rarray.empty () in 975 - let dec_add _i v a = Jsont_base.Rarray.add_last v a in 976 - let dec_finish _meta _len a = Jsont_base.Rarray.to_array a in 974 + let dec_empty () = Json_base.Rarray.empty () in 975 + let dec_add _i v a = Json_base.Rarray.add_last v a in 976 + let dec_finish _meta _len a = Json_base.Rarray.to_array a in 977 977 let enc = { enc = array_enc } in 978 978 map ?kind ?doc ~dec_empty ?dec_skip ~dec_add ~dec_finish ~enc elt 979 979 980 - type ('a, 'b, 'c) bigarray_builder = ('a, 'b, 'c) Jsont_base.Rbigarray1.t 980 + type ('a, 'b, 'c) bigarray_builder = ('a, 'b, 'c) Json_base.Rbigarray1.t 981 981 982 982 let bigarray_map ?kind ?doc ?dec_skip k l elt = 983 - let dec_empty _meta = Jsont_base.Rbigarray1.empty k l in 984 - let dec_add _i v a = Jsont_base.Rbigarray1.add_last v a in 985 - let dec_finish _meta _len a = Jsont_base.Rbigarray1.to_bigarray a in 983 + let dec_empty _meta = Json_base.Rbigarray1.empty k l in 984 + let dec_add _i v a = Json_base.Rbigarray1.add_last v a in 985 + let dec_finish _meta _len a = Json_base.Rbigarray1.to_bigarray a in 986 986 let enc f acc a = 987 987 let acc = ref acc in 988 988 for i = 0 to Bigarray.Array1.dim a - 1 do ··· 1123 1123 Repr.Array (Array.map ~kind ?doc ~dec_empty ~dec_add ~dec_finish ~enc t) 1124 1124 1125 1125 let tn ?(kind = "") ?doc ~n elt = 1126 - let dec_empty () = Jsont_base.Rarray.empty () in 1127 - let dec_add _i v a = Jsont_base.Rarray.add_last v a in 1126 + let dec_empty () = Json_base.Rarray.empty () in 1127 + let dec_add _i v a = Json_base.Rarray.add_last v a in 1128 1128 let dec_finish meta _len a = 1129 - let len = Jsont_base.Rarray.length a in 1129 + let len = Json_base.Rarray.length a in 1130 1130 if len <> n then error_tuple_size meta kind ~exp:n len 1131 - else Jsont_base.Rarray.to_array a 1131 + else Json_base.Rarray.to_array a 1132 1132 in 1133 1133 let enc = { Array.enc = Array.array_enc } in 1134 1134 Repr.Array (Array.map ~kind ?doc ~dec_empty ~dec_add ~dec_finish ~enc elt) ··· 1254 1254 1255 1255 let check_case_mem map cases ~dec_absent ~tag_compare ~tag_to_string = 1256 1256 match map.shape with 1257 - | Object_cases _ -> invalid_arg "Multiple calls to Jsont.Object.case_mem" 1257 + | Object_cases _ -> invalid_arg "Multiple calls to Json.Object.case_mem" 1258 1258 | _ -> ( 1259 1259 match dec_absent with 1260 1260 | None -> () ··· 1348 1348 let set_shape_unknown_mems shape u = 1349 1349 match shape with 1350 1350 | Object_basic (Unknown_keep _) | Object_cases (Some (Unknown_keep _), _) -> 1351 - invalid_arg "Jsont.Object.keep_unknown already called on object" 1351 + invalid_arg "Json.Object.keep_unknown already called on object" 1352 1352 | Object_basic _ -> Object_basic u 1353 1353 | Object_cases (_, cases) -> Object_cases (Some u, cases) 1354 1354 ··· 1552 1552 let int64_as_string ?(meta = Meta.none) v = String (Int64.to_string v, meta) 1553 1553 1554 1554 let int64 ?(meta = Meta.none) v = 1555 - if Jsont_base.Number.can_store_exact_int64 v then 1555 + if Json_base.Number.can_store_exact_int64 v then 1556 1556 Number (Int64.to_float v, meta) 1557 1557 else String (Int64.to_string v, meta) 1558 1558 1559 1559 let int_as_string ?(meta = Meta.none) i = String (Int.to_string i, meta) 1560 1560 1561 1561 let int ?(meta = Meta.none) v = 1562 - if Jsont_base.Number.can_store_exact_int v then Number (Int.to_float v, meta) 1562 + if Json_base.Number.can_store_exact_int v then Number (Int.to_float v, meta) 1563 1563 else String (Int.to_string v, meta) 1564 1564 1565 1565 (* Strings *)
+49 -49
ocaml-jsont/lib/jsont.mli ocaml-json/lib/json.mli
··· 247 247 (** JSON paths. 248 248 249 249 Paths are used for keeping track of erroring {{!Error.Context.t}contexts} 250 - and for specifying {{!Jsont.queries} query and update} locations. *) 250 + and for specifying {{!Json.queries} query and update} locations. *) 251 251 module Path : sig 252 252 (** {1:indices Indices} *) 253 253 ··· 381 381 (** JSON error contexts. *) 382 382 module Context : sig 383 383 type index = string node * Path.index 384 - (** The type for context indices. The {{!Jsont.kinded_sort}kinded sort} of 384 + (** The type for context indices. The {{!Json.kinded_sort}kinded sort} of 385 385 an array or object and its index. *) 386 386 387 387 type t = index list ··· 396 396 397 397 val push_array : string node -> int node -> t -> t 398 398 (** [push_array kinded_sort n ctx] wraps [ctx] as the [n]th element of an 399 - array of {{!Jsont.kinded_sort}kinded sort} [kinded_sort]. *) 399 + array of {{!Json.kinded_sort}kinded sort} [kinded_sort]. *) 400 400 401 401 val push_object : string node -> string node -> t -> t 402 402 (** [push_object kinded_sort n ctx] wraps [ctx] as the member named [n] of 403 - an object of {{!Jsont.kinded_sort}kinded sort} [kinded_sort]. *) 403 + an object of {{!Json.kinded_sort}kinded sort} [kinded_sort]. *) 404 404 end 405 405 406 406 type t = Context.t * Meta.t * kind ··· 427 427 428 428 val push_array : string node -> int node -> t -> 'a 429 429 (** [push_array kinded_sort n e] contextualises [e] as an error in the [n]th 430 - element of an array of {{!Jsont.kinded_sort}kinded sort} [kinded_sort]. *) 430 + element of an array of {{!Json.kinded_sort}kinded sort} [kinded_sort]. *) 431 431 432 432 val push_object : string node -> string node -> t -> 'a 433 433 (** [push_object kinded_sort n e] contextualises [e] as an error in the member 434 - [n] of an object of {{!Jsont.kinded_sort}kinded sort} [kinded_sort]. *) 434 + [n] of an object of {{!Json.kinded_sort}kinded sort} [kinded_sort]. *) 435 435 436 436 val adjust_context : 437 437 first_byte:Textloc.byte_pos -> first_line:Textloc.line_pos -> t -> 'a ··· 520 520 unconditionally errors. 521 521 - [enc_meta] is used to recover JSON metadata (source text layout 522 522 information) from a value to encode. The default unconditionnaly returns 523 - {!Jsont.Meta.none}. 523 + {!Json.Meta.none}. 524 524 525 525 {{!decenc}These functions} can be used to quickly devise [dec] and [enc] 526 526 functions from standard OCaml conversion interfaces. *) ··· 535 535 536 536 val null : (unit, 'a) map -> 'a t 537 537 (** [null map] maps with [map] JSON nulls represented by [()] to values of 538 - type ['a]. See also {!Jsont.null}. *) 538 + type ['a]. See also {!Json.null}. *) 539 539 540 540 val bool : (bool, 'a) map -> 'a t 541 541 (** [bool map] maps with [map] JSON booleans represented by [bool] values to 542 - values of type ['a]. See also {!Jsont.bool}. *) 542 + values of type ['a]. See also {!Json.bool}. *) 543 543 544 544 val number : (float, 'a) map -> 'a t 545 545 (** [number map] maps with [map] JSON nulls or numbers represented by [float] ··· 547 547 nulls to {!Float.nan} and lossily encodes any 548 548 {{!Float.is_finite}non-finite} to JSON null 549 549 ({{!page-cookbook.non_finite_numbers}explanation}). See also 550 - {!Jsont.number}. *) 550 + {!Json.number}. *) 551 551 552 552 val string : (string, 'a) map -> 'a t 553 553 (** [string map] maps with [map] {e unescaped} JSON strings represented by 554 554 UTF-8 encoded [string] values to values of type ['a]. See also 555 - {!Jsont.string}. *) 555 + {!Json.string}. *) 556 556 557 557 (** {1:decenc Decoding and encoding functions} 558 558 559 559 These function create suitable [dec] and [enc] functions to give to 560 560 {!val-map} from standard OCaml conversion interfaces. See also 561 - {!Jsont.of_of_string}. *) 561 + {!Json.of_of_string}. *) 562 562 563 563 val dec : ('a -> 'b) -> Meta.t -> 'a -> 'b 564 564 (** [dec f] is a decoding function from [f]. This assumes [f] never fails. *) ··· 804 804 'a t -> 805 805 ('a list, 'a, 'a list) map 806 806 (** [list_map elt] maps JSON arrays with elements of type [elt] to [list] 807 - values. See also {!Jsont.list}. *) 807 + values. See also {!Json.list}. *) 808 808 809 809 type 'a array_builder 810 810 (** The type for array builders. *) ··· 816 816 'a t -> 817 817 ('a array, 'a, 'a array_builder) map 818 818 (** [array_map elt] maps JSON arrays with elements of type [elt] to [array] 819 - values. See also {!Jsont.array}. *) 819 + values. See also {!Json.array}. *) 820 820 821 821 type ('a, 'b, 'c) bigarray_builder 822 822 (** The type for bigarray_builders. *) ··· 830 830 'a t -> 831 831 (('a, 'b, 'c) Bigarray.Array1.t, 'a, ('a, 'b, 'c) bigarray_builder) map 832 832 (** [bigarray k l elt] maps JSON arrays with elements of type [elt] to 833 - bigarray values of kind [k] and layout [l]. See also {!Jsont.bigarray}. *) 833 + bigarray values of kind [k] and layout [l]. See also {!Json.bigarray}. *) 834 834 835 835 (** {1:types JSON types} *) 836 836 ··· 954 954 955 955 (** Member maps. 956 956 957 - Usually it's better to use {!Jsont.Object.mem} or {!Jsont.Object.opt_mem} 957 + Usually it's better to use {!Json.Object.mem} or {!Json.Object.opt_mem} 958 958 directly. But this may be useful in certain abstraction contexts. *) 959 959 module Mem : sig 960 960 type ('o, 'dec) object_map := ('o, 'dec) map ··· 971 971 string -> 972 972 'a t -> 973 973 ('o, 'a) map 974 - (** See {!Jsont.Object.mem}. *) 974 + (** See {!Json.Object.mem}. *) 975 975 976 976 val app : ('o, 'a -> 'b) object_map -> ('o, 'a) map -> ('o, 'b) object_map 977 977 (** [app map mmap] applies the member map [mmap] to the contructor of the ··· 1013 1013 (** [opt_mem name t map] is: 1014 1014 {[ 1015 1015 let dec_absent = None and enc_omit = Option.is_none in 1016 - Jsont.Object.mem name (Jsont.some t) map ~dec_absent ~enc_omit 1016 + Json.Object.mem name (Json.some t) map ~dec_absent ~enc_omit 1017 1017 ]} 1018 1018 A shortcut to represent optional members of type ['a] with ['a option] 1019 1019 values. *) ··· 1030 1030 module Case : sig 1031 1031 (** {1:maps Maps} *) 1032 1032 1033 - type 'a jsont := 'a t 1033 + type 'a codec := 'a t 1034 1034 1035 1035 type ('cases, 'case, 'tag) map 1036 1036 (** The type for mapping a case object represented by ['case] belonging to a ··· 1038 1038 member of type ['tag]. *) 1039 1039 1040 1040 val map : 1041 - ?dec:('case -> 'cases) -> 'tag -> 'case jsont -> ('cases, 'case, 'tag) map 1041 + ?dec:('case -> 'cases) -> 'tag -> 'case codec -> ('cases, 'case, 'tag) map 1042 1042 (** [map ~dec v obj] defines the object map [obj] as being the case for the 1043 1043 tag value [v] of the case member. [dec] indicates how to inject the 1044 1044 object case into the type common to all cases. ··· 1121 1121 module Mems : sig 1122 1122 (** {1:maps Maps} *) 1123 1123 1124 - type 'a jsont := 'a t 1124 + type 'a codec := 'a t 1125 1125 1126 1126 type ('mems, 'a) enc = { 1127 1127 enc : ··· 1142 1142 ?dec_add:(Meta.t -> string -> 'a -> 'builder -> 'builder) -> 1143 1143 ?dec_finish:(Meta.t -> 'builder -> 'mems) -> 1144 1144 ?enc:('mems, 'a) enc -> 1145 - 'a jsont -> 1145 + 'a codec -> 1146 1146 ('mems, 'a, 'builder) map 1147 1147 (** [map type'] maps unknown members of uniform type ['a] to values of type 1148 1148 ['mems] built with type ['builder]. ··· 1167 1167 val string_map : 1168 1168 ?kind:string -> 1169 1169 ?doc:string -> 1170 - 'a jsont -> 1170 + 'a codec -> 1171 1171 ('a Stdlib.Map.Make(String).t, 'a, 'a Stdlib.Map.Make(String).t) map 1172 1172 (** [string_map t] collects unknown member by name and types their values 1173 1173 with [t]. See {!keep_unknown} and {!as_string_map}. *) ··· 1191 1191 (** [keep_unknown mems map] makes [map] keep unknown member with [mems]. 1192 1192 Raises [Invalid_argument] if {!keep_unknown} was already specified on 1193 1193 [map]. See this {{!page-cookbook.keeping}this example}, {!Mems.string_map} 1194 - and {!Jsont.json_mems}. *) 1194 + and {!Json.json_mems}. *) 1195 1195 1196 1196 (** {1:types JSON types} *) 1197 1197 1198 1198 val as_string_map : 1199 1199 ?kind:string -> ?doc:string -> 'a t -> 'a Stdlib.Map.Make(String).t t 1200 1200 (** [as_string_map t] maps object to key-value maps of type [t]. See also 1201 - {!Mems.string_map} and {!Jsont.json_mems}. *) 1201 + {!Mems.string_map} and {!Json.json_mems}. *) 1202 1202 1203 1203 val zero : unit t 1204 1204 (** [zero] ignores JSON objects on decoding and encodes an empty object. *) ··· 1241 1241 - [enc] encodes values of type ['b] to values of type ['a]. Can be omitted 1242 1242 if the result is only used for decoding. The default errors. 1243 1243 1244 - For mapping base types use {!Jsont.Base.map}. *) 1244 + For mapping base types use {!Json.Base.map}. *) 1245 1245 1246 1246 val iter : 1247 1247 ?kind:string -> ··· 1299 1299 module Json : sig 1300 1300 (** {1:json JSON values} *) 1301 1301 1302 - type 'a jsont := 'a t 1302 + type 'a codec := 'a t 1303 1303 1304 1304 type 'a cons = ?meta:Meta.t -> 'a -> json 1305 1305 (** The type for constructing JSON values from an OCaml value of type ['a]. 1306 1306 [meta] defaults to {!Meta.none}. *) 1307 1307 1308 1308 type t = json 1309 - (** See {!Jsont.val-json}. *) 1309 + (** See {!Json.val-json}. *) 1310 1310 1311 1311 val meta : json -> Meta.t 1312 1312 (** [meta v] is the metadata of value [v]. *) ··· 1338 1338 - {!Meta.t} values are ignored. *) 1339 1339 1340 1340 val pp : t fmt 1341 - (** See {!Jsont.pp_json}. *) 1341 + (** See {!Json.pp_json}. *) 1342 1342 1343 1343 (** {2:null Nulls and options} *) 1344 1344 ··· 1361 1361 1362 1362 val any_float : float cons 1363 1363 (** [any_float v] is [number v] if {!Float.is_finite}[ v] is [true] and 1364 - [string (Float.to_string v)] otherwise. See {!Jsont.any_float}. *) 1364 + [string (Float.to_string v)] otherwise. See {!Json.any_float}. *) 1365 1365 1366 1366 val int32 : int32 cons 1367 1367 (** [int32] is [i] as a JSON number. *) ··· 1418 1418 1419 1419 (** {1:decode Decode} *) 1420 1420 1421 - val decode : 'a jsont -> json -> ('a, string) result 1421 + val decode : 'a codec -> json -> ('a, string) result 1422 1422 (** [decode t j] decodes a value from the generic JSON [j] according to type 1423 1423 [t]. *) 1424 1424 1425 - val decode' : 'a jsont -> json -> ('a, Error.t) result 1425 + val decode' : 'a codec -> json -> ('a, Error.t) result 1426 1426 (** [decode'] is like {!val-decode} but preserves the error structure. *) 1427 1427 1428 1428 (** {1:encode Encode} *) 1429 1429 1430 - val encode : 'a jsont -> 'a -> (json, string) result 1430 + val encode : 'a codec -> 'a -> (json, string) result 1431 1431 (** [encode t v] encodes a generic JSON value for [v] according to type [t]. 1432 1432 *) 1433 1433 1434 - val encode' : 'a jsont -> 'a -> (json, Error.t) result 1434 + val encode' : 'a codec -> 'a -> (json, Error.t) result 1435 1435 (** [encode'] is like {!val-encode} but preserves the error structure. *) 1436 1436 1437 1437 (** {1:recode Recode} *) 1438 1438 1439 - val recode : 'a jsont -> json -> (json, string) result 1439 + val recode : 'a codec -> json -> (json, string) result 1440 1440 (** [recode t v] decodes [v] with [t] and encodes it with [t]. *) 1441 1441 1442 - val recode' : 'a jsont -> json -> (json, Error.t) result 1442 + val recode' : 'a codec -> json -> (json, Error.t) result 1443 1443 (** [recode'] is like {!val-recode} but preserves the error structure. *) 1444 1444 1445 - val update : 'a jsont -> json -> json 1446 - (** [update] is like {!val-recode} but raises {!Jsont.exception-Error}. *) 1445 + val update : 'a codec -> json -> json 1446 + (** [update] is like {!val-recode} but raises {!Json.exception-Error}. *) 1447 1447 1448 1448 (** {1:errors Errors} *) 1449 1449 ··· 1451 1451 (** [error_sort ~exp fnd] errors when sort [exp] was expected but generic JSON 1452 1452 [fnd] was found. *) 1453 1453 1454 - val error_type : 'a jsont -> json -> 'a 1454 + val error_type : 'a codec -> json -> 'a 1455 1455 (** [error_type t fnd] errors when the type expected by [t] does not match 1456 1456 [fnd]. *) 1457 1457 end ··· 1618 1618 (** {1:fmt Formatting} *) 1619 1619 1620 1620 (** The type for specifying JSON encoding formatting. See for example 1621 - {!Jsont_bytesrw.val-encode}. *) 1621 + {!Json_bytesrw.val-encode}. *) 1622 1622 type format = 1623 1623 | Minify (** Compact. No whitespace, no newlines. *) 1624 1624 | Indent (** Indented output (not necessarily pretty). *) ··· 1676 1676 This representation may change even between minor versions of the library. 1677 1677 It can be used to devise new processors on JSON types. 1678 1678 1679 - Processors should be ready to catch the {!Jsont.exception-Error} exception 1679 + Processors should be ready to catch the {!Json.exception-Error} exception 1680 1680 when they invoke functional members of the representation. 1681 1681 1682 1682 Processors should make sure they interpret mappings correctly. In ··· 1685 1685 1686 1686 See the source of {!Json.decode'} and {!Json.encode'} for a simple example 1687 1687 on how to process this representation. The 1688 - {{:https://erratique.ch/repos/jsont/tree/paper}paper} in the Jsont source 1688 + {{:https://erratique.ch/repos/jsont/tree/paper}paper} in the Json source 1689 1689 repository may also help to understand this menagerie of types. *) 1690 1690 module Repr : sig 1691 1691 type 'a t' := 'a t ··· 1961 1961 1962 1962 val unsafe_to_t : 'a t -> 'a t' 1963 1963 (** [unsafe_to_t r] converts the representation to a type [r]. It is unsafe 1964 - because constructors of the {!Jsont} module do maintain some invariants. 1964 + because constructors of the {!Json} module do maintain some invariants. 1965 1965 *) 1966 1966 1967 1967 (** {1:kinds Kinds and doc} *) 1968 1968 1969 1969 val kinded_sort : 'a t -> string 1970 - (** [kinded_sort t] is kinded sort of [t], see {!Jsont.kinded_sort}. *) 1970 + (** [kinded_sort t] is kinded sort of [t], see {!Json.kinded_sort}. *) 1971 1971 1972 1972 val array_map_kinded_sort : ('a, 'elt, 'builder) array_map -> string 1973 1973 (** [array_map_kinded_sort map] is like {!kinded_sort} but acts directly on ··· 1981 1981 (** [pp_kind] formats kinds. *) 1982 1982 1983 1983 val doc : 'a t -> string 1984 - (** See {!Jsont.doc}. *) 1984 + (** See {!Json.doc}. *) 1985 1985 1986 1986 val with_doc : ?kind:string -> ?doc:string -> 'a t -> 'a t 1987 - (** See {!Jsont.with_doc}. *) 1987 + (** See {!Json.with_doc}. *) 1988 1988 1989 1989 (** {1:errors Errors} *) 1990 1990 ··· 2024 2024 (** {1:toolbox Processor toolbox} *) 2025 2025 2026 2026 val object_meta_arg : Meta.t Type.Id.t 2027 - (** [object_meta_arg] holds the {!Jsont.Object.mem} to *) 2027 + (** [object_meta_arg] holds the {!Json.Object.mem} to *) 2028 2028 2029 2029 (** Heterogeneous dictionaries. *) 2030 2030 module Dict : sig ··· 2055 2055 Dict.t -> 2056 2056 unknown_mems_option * Dict.t 2057 2057 (** [override_unknown_mems ~by current dict] preforms the unknown member 2058 - overriding logic for {!Jsont.Object.Case} objects. In particular if 2059 - [current] is a {!Jsont.Object.Mems.val-map} it adds an empty one in [dict] 2058 + overriding logic for {!Json.Object.Case} objects. In particular if 2059 + [current] is a {!Json.Object.Mems.val-map} it adds an empty one in [dict] 2060 2060 so that the associated decoding function does not fail. *) 2061 2061 2062 2062 val finish_object_decode :
ocaml-jsont/lib/jsont_base.ml ocaml-json/lib/json_base.ml
+5 -5
ocaml-jsont/lib/jsont_base.mli ocaml-json/lib/json_base.mli
··· 3 3 SPDX-License-Identifier: ISC 4 4 ---------------------------------------------------------------------------*) 5 5 6 - (** Low-level internal tools for {!Jsont}. *) 6 + (** Low-level internal tools for {!Json}. *) 7 7 8 8 val string_subrange : ?first:int -> ?last:int -> string -> string 9 9 val binary_string_of_hex : string -> (string, string) result ··· 78 78 val json_string : string t 79 79 end 80 80 81 - (** See {!Jsont.Textloc} *) 81 + (** See {!Json.Textloc} *) 82 82 module Textloc : sig 83 83 type fpath = string 84 84 ··· 135 135 136 136 type 'a fmt = Stdlib.Format.formatter -> 'a -> unit 137 137 138 - (** See {!Jsont.Meta} *) 138 + (** See {!Json.Meta} *) 139 139 module Meta : sig 140 140 type t 141 141 ··· 171 171 val in_exact_int64_range : float -> bool 172 172 end 173 173 174 - (** See {!Jsont.Path} *) 174 + (** See {!Json.Path} *) 175 175 module Path : sig 176 176 type index = Mem of string node | Nth of int node 177 177 ··· 190 190 val pp_trace : t fmt 191 191 end 192 192 193 - (** See {!Jsont.Sort} *) 193 + (** See {!Json.Sort} *) 194 194 module Sort : sig 195 195 type t = Null | Bool | Number | String | Array | Object 196 196
ocaml-jsont/test/cookbook.ml ocaml-json/test/cookbook.ml
ocaml-jsont/test/geojson.ml ocaml-json/test/geojson.ml
ocaml-jsont/test/json_rpc.ml ocaml-json/test/json_rpc.ml
ocaml-jsont/test/jsont_tool.ml ocaml-json/test/jsont_tool.ml
ocaml-jsont/test/quickstart.ml ocaml-json/test/quickstart.ml
ocaml-jsont/test/test_brr.ml ocaml-json/test/test_brr.ml
ocaml-jsont/test/test_bytesrw.ml ocaml-json/test/test_bytesrw.ml
ocaml-jsont/test/test_common.ml ocaml-json/test/test_common.ml
ocaml-jsont/test/test_common_samples.ml ocaml-json/test/test_common_samples.ml
ocaml-jsont/test/test_json.ml ocaml-json/test/test_json.ml
ocaml-jsont/test/test_jsont_tool.ml ocaml-json/test/test_jsont_tool.ml
ocaml-jsont/test/test_seriot_suite.ml ocaml-json/test/test_seriot_suite.ml
ocaml-jsont/test/topojson.ml ocaml-json/test/topojson.ml
ocaml-jsont/test/trials.ml ocaml-json/test/trials.ml