6060
6161- Raises a SyntaxError (Exn.t) if the string isn't valid JSON. 
6262*/ 
63- @raises (Exn .t )
64- @val 
63+ @raises (Exn .t ) @val 
6564external  parseOrThrow : (string , ~reviver : (string , t ) =>  t = ?) =>  t  =  "JSON.parse" 
6665
6766/**  
@@ -107,11 +106,45 @@ try {
107106
108107- Raises a SyntaxError (Exn.t) if the string isn't valid JSON. 
109108*/ 
110- @deprecated ("Use `parseOrThrow` instead" )
111- @raises (Exn .t )
112- @val 
109+ @deprecated ("Use `parseOrThrow` instead" ) @raises (Exn .t ) @val 
113110external  parseExn : (string , ~reviver : (string , t ) =>  t = ?) =>  t  =  "JSON.parse" 
114111
112+ /**  
113+ `parseExnWithReviver(string, reviver)`  
114+ 
115+ Parses a JSON string or throws a JavaScript exception (SyntaxError), if the string isn't valid. 
116+ The reviver describes how the value should be transformed. It is a function which receives a key and a value. 
117+ It returns a JSON type. 
118+ 
119+ ## Examples 
120+ ```rescript 
121+ let reviver = (_, value: JSON.t) => 
122+   switch value { 
123+   | String(string) => string->String.toUpperCase->JSON.Encode.string 
124+   | Number(number) => (number *. 2.0)->JSON.Encode.float 
125+   | _ => value 
126+   } 
127+ 
128+ let jsonString = `{"hello":"world","someNumber":21}` 
129+ 
130+ JSON.parseExnWithReviver(jsonString, reviver)->Console.log 
131+ // { hello: 'WORLD', someNumber: 42 } 
132+ 
133+ try { 
134+   JSON.parseExnWithReviver("", reviver)->Console.log 
135+   // error 
136+ } catch { 
137+ | JsExn(_) => Console.log("error") 
138+ } 
139+ ``` 
140+ 
141+ ## Exceptions  
142+ 
143+ - Raises a SyntaxError if the string is not a valid JSON. 
144+ */ 
145+ @deprecated ("Use `parseOrThrow` with optional parameter instead" ) @raises (Exn .t ) @val 
146+ external  parseExnWithReviver : (string , (string , t ) =>  t ) =>  t  =  "JSON.parse" 
147+ 
115148/**  
116149`stringify(json, ~replacer=?, ~space=?)`  
117150
@@ -181,8 +214,7 @@ JSON.stringifyWithIndent(json, 2)
181214// } 
182215``` 
183216*/ 
184- @deprecated ("Use `stringify` with optional parameter instead" )
185- @val 
217+ @deprecated ("Use `stringify` with optional parameter instead" ) @val 
186218external  stringifyWithIndent : (t , @as (json ` null` ) _ , int ) =>  string  =  "JSON.stringify" 
187219
188220/**  
@@ -214,8 +246,7 @@ JSON.stringifyWithReplacer(json, replacer)
214246// {"foo":"BAR","hello":"WORLD","someNumber":42} 
215247``` 
216248*/ 
217- @deprecated ("Use `stringify` with optional parameter instead" )
218- @val 
249+ @deprecated ("Use `stringify` with optional parameter instead" ) @val 
219250external  stringifyWithReplacer : (t , (string , t ) =>  t ) =>  string  =  "JSON.stringify" 
220251
221252/**  
@@ -251,8 +282,7 @@ JSON.stringifyWithReplacerAndIndent(json, replacer, 2)
251282// } 
252283``` 
253284*/ 
254- @deprecated ("Use `stringify` with optional parameters instead" )
255- @val 
285+ @deprecated ("Use `stringify` with optional parameters instead" ) @val 
256286external  stringifyWithReplacerAndIndent : (t , (string , t ) =>  t , int ) =>  string  =  "JSON.stringify" 
257287
258288/**  
@@ -275,8 +305,7 @@ JSON.stringifyWithFilter(json, ["foo", "someNumber"])
275305// {"foo":"bar","someNumber":42} 
276306``` 
277307*/ 
278- @deprecated ("Use `stringify` with optional parameter instead" )
279- @val 
308+ @deprecated ("Use `stringify` with optional parameter instead" ) @val 
280309external  stringifyWithFilter : (t , array <string >) =>  string  =  "JSON.stringify" 
281310
282311/**  
@@ -302,8 +331,7 @@ JSON.stringifyWithFilterAndIndent(json, ["foo", "someNumber"], 2)
302331// } 
303332``` 
304333*/ 
305- @deprecated ("Use `stringify` with optional parameters instead" )
306- @val 
334+ @deprecated ("Use `stringify` with optional parameters instead" ) @val 
307335external  stringifyWithFilterAndIndent : (t , array <string >, int ) =>  string  =  "JSON.stringify" 
308336
309337/**  
@@ -372,8 +400,7 @@ switch BigInt.fromInt(0)->JSON.stringifyAny {
372400- Raises a TypeError if the value contains circular references. 
373401- Raises a TypeError if the value contains `BigInt`s. 
374402*/ 
375- @raises (Exn .t )
376- @val 
403+ @raises (Exn .t ) @val 
377404external  stringifyAny : ('a , ~replacer : replacer = ?, ~space : int = ?) =>  option <string > = 
378405  "JSON.stringify" 
379406
@@ -416,9 +443,7 @@ switch BigInt.fromInt(0)->JSON.stringifyAny {
416443- Raises a TypeError if the value contains circular references. 
417444- Raises a TypeError if the value contains `BigInt`s. 
418445*/ 
419- @deprecated ("Use `stringifyAny` with optional parameter instead" )
420- @raises (Exn .t )
421- @val 
446+ @deprecated ("Use `stringifyAny` with optional parameter instead" ) @raises (Exn .t ) @val 
422447external  stringifyAnyWithIndent : ('a , @as (json ` null` ) _ , int ) =>  option <string > =  "JSON.stringify" 
423448
424449/**  
@@ -465,9 +490,7 @@ switch BigInt.fromInt(0)->JSON.stringifyAny {
465490- Raises a TypeError if the value contains circular references. 
466491- Raises a TypeError if the value contains `BigInt`s. 
467492*/ 
468- @deprecated ("Use `stringifyAny` with optional parameter instead" )
469- @raises 
470- @val 
493+ @deprecated ("Use `stringifyAny` with optional parameter instead" ) @raises  @val 
471494external  stringifyAnyWithReplacer : ('a , (string , t ) =>  t ) =>  option <string > =  "JSON.stringify" 
472495
473496/**  
@@ -515,9 +538,7 @@ switch BigInt.fromInt(0)->JSON.stringifyAny {
515538- Raises a TypeError if the value contains circular references. 
516539- Raises a TypeError if the value contains `BigInt`s. 
517540*/ 
518- @deprecated ("Use `stringifyAny` with optional parameters instead" )
519- @raises 
520- @val 
541+ @deprecated ("Use `stringifyAny` with optional parameters instead" ) @raises  @val 
521542external  stringifyAnyWithReplacerAndIndent : ('a , (string , t ) =>  t , int ) =>  option <string > = 
522543  "JSON.stringify" 
523544
@@ -556,9 +577,7 @@ switch BigInt.fromInt(0)->JSON.stringifyAny {
556577- Raises a TypeError if the value contains circular references. 
557578- Raises a TypeError if the value contains `BigInt`s. 
558579*/ 
559- @deprecated ("Use `stringifyAny` with optional parameter instead" )
560- @raises 
561- @val 
580+ @deprecated ("Use `stringifyAny` with optional parameter instead" ) @raises  @val 
562581external  stringifyAnyWithFilter : ('a , array <string >) =>  string  =  "JSON.stringify" 
563582
564583/**  
@@ -611,9 +630,7 @@ switch BigInt.fromInt(0)->JSON.stringifyAny {
611630- Raises a TypeError if the value contains circular references. 
612631- Raises a TypeError if the value contains `BigInt`s. 
613632*/ 
614- @deprecated ("Use `stringifyAny` with optional parameters instead" )
615- @raises 
616- @val 
633+ @deprecated ("Use `stringifyAny` with optional parameters instead" ) @raises  @val 
617634external  stringifyAnyWithFilterAndIndent : ('a , array <string >, int ) =>  string  =  "JSON.stringify" 
618635
619636module  Classify : {
0 commit comments