summary refs log tree commit diff stats
path: root/lib/std
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-05-11 12:09:17 -0700
committerGitHub <noreply@github.com>2021-05-11 21:09:17 +0200
commita770c98e272109968203403009bfb617a5f2d33a (patch)
tree7cbf12cc404db0855fbf6ac8142771eebf20331a /lib/std
parente60672141a971da878dac6781fb907b9c520c219 (diff)
downloadNim-a770c98e272109968203403009bfb617a5f2d33a.tar.gz
jsonutils: support set (#17994)
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/jsonutils.nim6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/std/jsonutils.nim b/lib/std/jsonutils.nim
index 4c27bc9f2..59c3b0f7d 100644
--- a/lib/std/jsonutils.nim
+++ b/lib/std/jsonutils.nim
@@ -214,6 +214,10 @@ proc fromJson*[T](a: var T, b: JsonNode, opt = Joptions()) =
     for ai in mitems(a):
       fromJson(ai, b[i], opt)
       i.inc
+  elif T is set:
+    type E = typeof(for ai in a: ai)
+    for val in b.getElems:
+      incl a, jsonTo(val, E)
   elif T is seq:
     a.setLen b.len
     for i, val in b.getElems:
@@ -268,7 +272,7 @@ proc toJson*[T](a: T): JsonNode =
   elif T is ref | ptr:
     if system.`==`(a, nil): result = newJNull()
     else: result = toJson(a[])
-  elif T is array | seq:
+  elif T is array | seq | set:
     result = newJArray()
     for ai in a: result.add toJson(ai)
   elif T is pointer: result = toJson(cast[int](a))