Declarative JSON data manipulation for OCaml
0
fork

Configure Feed

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

toml: rename from tomlt, split raw AST into Value submodule

Drops the "t" suffix and follows the value/codec/toml/core pattern
(jsont.json_base style). The internal raw TOML module moves from
[Toml] to [Value] (file: lib/value.ml, was lib/toml.ml) to make room
for the top-level Toml facade (file: lib/toml.ml, was lib/tomlt.ml).

External callers now reach the raw AST through [Toml.Value.X] instead
of [Tomlt.Toml.X]. Every downstream reference updated in lockstep.

+39 -33
+1 -1
json.opam
··· 14 14 homepage: "https://tangled.org/gazagnaire.org/ocaml-jsont" 15 15 bug-reports: "https://tangled.org/gazagnaire.org/ocaml-jsont/issues" 16 16 depends: [ 17 - "ocaml" {>= "4.14"} 17 + "ocaml" {>= "5.1"} 18 18 "dune" {>= "3.21" & >= "3.21"} 19 19 "bytesrw" {>= "0.1.0"} 20 20 "alcotest" {with-test}
+15 -12
lib/brr/json_brr.mli
··· 19 19 20 20 (** {1:decode Decode} *) 21 21 22 - val decode : 'a Json.t -> Jstr.t -> ('a, Jv.Error.t) result 22 + val decode : 'a Json.codec -> 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 Json.t -> Jstr.t -> ('a, Json.Error.t) result 25 + val decode' : 'a Json.codec -> 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 Json.t -> Jv.t -> ('a, Jv.Error.t) result 28 + val decode_jv : 'a Json.codec -> 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 Json.t -> Jv.t -> ('a, Json.Error.t) result 31 + val decode_jv' : 'a Json.codec -> 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:Json.format -> 'a Json.t -> 'a -> (Jstr.t, Jv.Error.t) result 37 + ?format:Json.format -> 'a Json.codec -> 'a -> (Jstr.t, Jv.Error.t) result 38 38 (** [encode t v] encodes [v] to JSON according to [t]. [format] specifies how 39 39 the JSON is formatted, defaults to {!Json.Minify}. The {!Json.Layout} format 40 40 is unsupported, {!Json.Indent} is used instead. *) 41 41 42 42 val encode' : 43 - ?format:Json.format -> 'a Json.t -> 'a -> (Jstr.t, Json.Error.t) result 43 + ?format:Json.format -> 'a Json.codec -> 'a -> (Jstr.t, Json.Error.t) result 44 44 (** [encode'] is like {!val-encode} but preserves the error structure. [format] 45 45 specifies how the JSON is formatted, defaults to {!Json.Minify}. The 46 46 {!Json.Layout} format is unsupported, {!Json.Indent} is used instead. *) 47 47 48 - val encode_jv : 'a Json.t -> 'a -> (Jv.t, Jv.Error.t) result 48 + val encode_jv : 'a Json.codec -> '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 Json.t -> 'a -> (Jv.t, Json.Error.t) result 51 + val encode_jv' : 'a Json.codec -> '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:Json.format -> 'a Json.t -> Jstr.t -> (Jstr.t, Jv.Error.t) result 57 + ?format:Json.format -> 'a Json.codec -> 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:Json.format -> 'a Json.t -> Jstr.t -> (Jstr.t, Json.Error.t) result 61 + ?format:Json.format -> 62 + 'a Json.codec -> 63 + Jstr.t -> 64 + (Jstr.t, Json.Error.t) result 62 65 (** [recode] is {!val-decode'} followed by {!val-encode'}. *) 63 66 64 - val recode_jv : 'a Json.t -> Jv.t -> (Jv.t, Jv.Error.t) result 67 + val recode_jv : 'a Json.codec -> Jv.t -> (Jv.t, Jv.Error.t) result 65 68 (** [recode] is {!val-decode} followed by {!val-encode}. *) 66 69 67 - val recode_jv' : 'a Json.t -> Jv.t -> (Jv.t, Json.Error.t) result 70 + val recode_jv' : 'a Json.codec -> Jv.t -> (Jv.t, Json.Error.t) result 68 71 (** [recode] is {!val-decode_jv'} followed by {!encode_jv'}. *)
+12 -12
lib/bytesrw/json_bytesrw.mli
··· 22 22 ?layout:bool -> 23 23 ?locs:bool -> 24 24 ?file:Json.Textloc.fpath -> 25 - 'a Json.t -> 25 + 'a Json.codec -> 26 26 Bytes.Reader.t -> 27 27 ('a, string) result 28 28 (** [decode t r] decodes a value from [r] according to [t]. ··· 37 37 ?layout:bool -> 38 38 ?locs:bool -> 39 39 ?file:Json.Textloc.fpath -> 40 - 'a Json.t -> 40 + 'a Json.codec -> 41 41 Bytes.Reader.t -> 42 42 ('a, Json.Error.t) result 43 43 (** [decode'] is like {!val-decode} but preserves the error structure. *) ··· 46 46 ?layout:bool -> 47 47 ?locs:bool -> 48 48 ?file:Json.Textloc.fpath -> 49 - 'a Json.t -> 49 + 'a Json.codec -> 50 50 string -> 51 51 ('a, string) result 52 52 (** [decode_string] is like {!val-decode} but decodes directly from a string. *) ··· 55 55 ?layout:bool -> 56 56 ?locs:bool -> 57 57 ?file:Json.Textloc.fpath -> 58 - 'a Json.t -> 58 + 'a Json.codec -> 59 59 string -> 60 60 ('a, Json.Error.t) result 61 61 (** [decode_string'] is like {!val-decode'} but decodes directly from a string. ··· 67 67 ?buf:Bytes.t -> 68 68 ?format:Json.format -> 69 69 ?number_format:Json.number_format -> 70 - 'a Json.t -> 70 + 'a Json.codec -> 71 71 'a -> 72 72 eod:bool -> 73 73 Bytes.Writer.t -> ··· 86 86 ?buf:Bytes.t -> 87 87 ?format:Json.format -> 88 88 ?number_format:Json.number_format -> 89 - 'a Json.t -> 89 + 'a Json.codec -> 90 90 'a -> 91 91 eod:bool -> 92 92 Bytes.Writer.t -> ··· 97 97 ?buf:Bytes.t -> 98 98 ?format:Json.format -> 99 99 ?number_format:Json.number_format -> 100 - 'a Json.t -> 100 + 'a Json.codec -> 101 101 'a -> 102 102 (string, string) result 103 103 (** [encode_string] is like {!val-encode} but writes to a string. *) ··· 106 106 ?buf:Bytes.t -> 107 107 ?format:Json.format -> 108 108 ?number_format:Json.number_format -> 109 - 'a Json.t -> 109 + 'a Json.codec -> 110 110 'a -> 111 111 (string, Json.Error.t) result 112 112 (** [encode_string'] is like {!val-encode'} but writes to a string. *) ··· 124 124 ?buf:Bytes.t -> 125 125 ?format:Json.format -> 126 126 ?number_format:Json.number_format -> 127 - 'a Json.t -> 127 + 'a Json.codec -> 128 128 Bytes.Reader.t -> 129 129 Bytes.Writer.t -> 130 130 eod:bool -> ··· 138 138 ?buf:Bytes.t -> 139 139 ?format:Json.format -> 140 140 ?number_format:Json.number_format -> 141 - 'a Json.t -> 141 + 'a Json.codec -> 142 142 Bytes.Reader.t -> 143 143 Bytes.Writer.t -> 144 144 eod:bool -> ··· 152 152 ?buf:Bytes.t -> 153 153 ?format:Json.format -> 154 154 ?number_format:Json.number_format -> 155 - 'a Json.t -> 155 + 'a Json.codec -> 156 156 string -> 157 157 (string, string) result 158 158 (** [recode] is {!decode_string} followed by {!recode_string}. *) ··· 164 164 ?buf:Bytes.t -> 165 165 ?format:Json.format -> 166 166 ?number_format:Json.number_format -> 167 - 'a Json.t -> 167 + 'a Json.codec -> 168 168 string -> 169 169 (string, Json.Error.t) result 170 170 (** [recode_string'] is like {!val-recode_string} but preserves the error
+10 -7
lib/json.ml
··· 156 156 | Number : (float, 'a) base_map -> 'a t 157 157 | String : (string, 'a) base_map -> 'a t 158 158 | Array : ('a, 'elt, 'builder) array_map -> 'a t 159 - | Object : ('o, 'o) object_map -> 'o codec 159 + | Object : ('o, 'o) object_map -> 'o t 160 160 | Any : 'a any_map -> 'a t 161 - | Map : ('a, 'b) map -> 'b codec 161 + | Map : ('a, 'b) map -> 'b t 162 162 | Rec : 'a t Lazy.t -> 'a t 163 - | Ignore : unit codec 163 + | Ignore : unit t 164 164 (** Skip-parse any JSON value without materialising its contents. The 165 165 bytesrw decoder dispatches to [skip_json_value], which advances past 166 166 the value at the byte level (balancing brackets, skipping string ··· 1385 1385 1386 1386 type name = string node 1387 1387 1388 - type mem = name * json 1388 + type mem = name * t 1389 1389 and object' = mem list 1390 1390 1391 1391 and t = ··· 1445 1445 (* Generic JSON *) 1446 1446 1447 1447 module Value = struct 1448 - type 'a cons = ?meta:Meta.t -> 'a -> t 1449 - type t = t 1448 + (* Local AST alias. Inside this module [open Repr] below shadows the 1449 + outer [t] with [Repr.t] (the codec GADT), so we preserve the AST 1450 + type under a name that isn't redefined. *) 1451 + type json = t 1452 + type 'a cons = ?meta:Meta.t -> 'a -> json 1450 1453 1451 1454 let meta = function 1452 1455 | Null (_, m) -> m ··· 1591 1594 1592 1595 (* Decoding *) 1593 1596 1594 - let rec decode : type a. a Repr.t -> t -> a = 1597 + let rec decode : type a. a Repr.t -> json -> a = 1595 1598 fun t j -> 1596 1599 match t with 1597 1600 | Null map -> (
+1 -1
lib/json.mli
··· 1472 1472 and ('array, 'elt, 'builder) array_map = { 1473 1473 kind : string; (** The kind of JSON array mapped (documentation). *) 1474 1474 doc : string; (** Documentation string for the JSON array. *) 1475 - elt : 'elt t; (** The type for the array elements. *) 1475 + elt : 'elt codec; (** The type for the array elements. *) 1476 1476 dec_empty : unit -> 'builder; 1477 1477 (** [dec_empty ()] creates a new empty array builder. *) 1478 1478 dec_skip : int -> 'builder -> bool;