Commits

Dmitry Grebeniuk  committed 72fc147

Cd_Json: ti_int: relaxed json parsing to floats without fractional part

  • Participants
  • Parent commits 4bb2abe

Comments (0)

Files changed (1)

File src/cd_Json.ml

 
 value () =
   ( ti_add_json (ti_int :> ti _)
-     ~json_to:Bl.int
-     ~json_from:Br.int
-     ()
+      ~json_to:Bl.int
+      ~json_from:
+        (fun j ->
+           try
+             Br.int j
+           with
+           [ (Jt.Json_error _) as e ->
+               let f = Br.number j in
+               let i = int_of_float f in
+               if f = float_of_int i
+               then i
+               else raise e
+           ]
+        )           
+      ()
   )
 ;