diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2021-05-16 14:54:10 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-16 23:54:10 +0200 |
commit | d83b25db1ebe7025d95dbce3978219948f5c49d3 (patch) | |
tree | a81315e50f5d0c1acd1c84ecb83fa26420369693 /lib/std | |
parent | 63fcb9e5f54fa6d3a65499abbed26a923f0dd337 (diff) | |
download | Nim-d83b25db1ebe7025d95dbce3978219948f5c49d3.tar.gz |
fix #18007: std/json now serializes nan,inf,-inf as strings instead of invalid json (#18026)
* fix #18007: std/json now serializes nan,inf,-inf as raw strings instead of invalid json * fix roundtrip * fix tests * fix changelog * simplify * add runnableExamples * fix typo [skip ci]
Diffstat (limited to 'lib/std')
-rw-r--r-- | lib/std/jsonutils.nim | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/std/jsonutils.nim b/lib/std/jsonutils.nim index 99f5ce9c6..1f49f60ed 100644 --- a/lib/std/jsonutils.nim +++ b/lib/std/jsonutils.nim @@ -12,6 +12,9 @@ runnableExamples: let a = (1.5'f32, (b: "b2", a: "a2"), 'x', @[Foo(t: true, z1: -3), nil], [{"name": "John"}.newStringTable]) let j = a.toJson assert j.jsonTo(typeof(a)).toJson == j + assert $[NaN, Inf, -Inf, 0.0, -0.0, 1.0, 1e-2].toJson == """["nan","inf","-inf",0.0,-0.0,1.0,0.01]""" + assert 0.0.toJson.kind == JFloat + assert Inf.toJson.kind == JString import json, strutils, tables, sets, strtabs, options |