@@ -22,6 +22,22 @@ open! Import
22
22
23
23
(* ***)
24
24
25
+ class type json = object
26
+ method parse : 'a. js_string t -> 'a meth
27
+
28
+ method parse_ :
29
+ 'a 'b 'c 'd. js_string t -> ('b t, js_string t -> 'c -> 'd) meth_callback -> 'a meth
30
+
31
+ method stringify : 'a. 'a -> js_string t meth
32
+
33
+ method stringify_ :
34
+ 'a 'b 'c 'd. 'a -> ('b, js_string t -> 'c -> 'd) meth_callback -> js_string t meth
35
+ end
36
+
37
+ let json : json Js.t = Unsafe. global##._JSON
38
+
39
+ (* ***)
40
+
25
41
(* The writing logic for basic types is copied from [lib/deriving_json]. *)
26
42
27
43
let write_string buffer s =
@@ -102,7 +118,7 @@ let rec write b v =
102
118
else if t = Obj. abstract_tag
103
119
then
104
120
(* Presumably a JavaScript value *)
105
- Buffer. add_string b (Js. to_string (Unsafe. global##._JSON ##stringify v))
121
+ Buffer. add_string b (Js. to_string (json ##stringify v))
106
122
else failwith (Printf. sprintf " Json.output: unsupported tag %d " t)
107
123
108
124
let to_json v =
@@ -112,20 +128,6 @@ let to_json v =
112
128
113
129
(* ***)
114
130
115
- class type json = object
116
- method parse : 'a. js_string t -> 'a meth
117
-
118
- method parse_ :
119
- 'a 'b 'c 'd. js_string t -> ('b t, js_string t -> 'c -> 'd) meth_callback -> 'a meth
120
-
121
- method stringify : 'a. 'a -> js_string t meth
122
-
123
- method stringify_ :
124
- 'a 'b 'c 'd. 'a -> ('b, js_string t -> 'c -> 'd) meth_callback -> js_string t meth
125
- end
126
-
127
- let json : json Js.t = Unsafe. global##._JSON
128
-
129
131
let input_reviver =
130
132
let reviver _this _key (value : Unsafe.any ) : Obj.t =
131
133
if Js. equals (typeof value) (string " string" )
0 commit comments