summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorLiam Sc <lscaife@protonmail.com>2019-07-03 06:06:22 +0000
committerAndreas Rumpf <rumpf_a@web.de>2019-07-03 08:06:22 +0200
commita157c2baefe63ba6ca0a0153e7ce664120f61f1e (patch)
tree3518c2253f0db5478e79f03cd64c24b560779758 /lib
parent20d0ef8afbd4b7b74c24f069841cce52cd5beaff (diff)
downloadNim-a157c2baefe63ba6ca0a0153e7ce664120f61f1e.tar.gz
Added 'keys' iterator to JsonNode (#11597) [feature]
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/json.nim6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/pure/json.nim b/lib/pure/json.nim
index 55e50dbe0..641f02069 100644
--- a/lib/pure/json.nim
+++ b/lib/pure/json.nim
@@ -779,6 +779,12 @@ iterator pairs*(node: JsonNode): tuple[key: string, val: JsonNode] =
   for key, val in pairs(node.fields):
     yield (key, val)
 
+iterator keys*(node: JsonNode): string =
+  ## Iterator for the keys in `node`. `node` has to be a JObject.
+  assert node.kind == JObject
+  for key in node.fields.keys:
+    yield key
+
 iterator mpairs*(node: var JsonNode): tuple[key: string, val: var JsonNode] =
   ## Iterator for the child elements of `node`. `node` has to be a JObject.
   ## Values can be modified