summary refs log tree commit diff stats
path: root/lib/pure/json.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-04-01 15:07:16 +0200
committerAraq <rumpf_a@web.de>2011-04-01 15:07:16 +0200
commit4741e8f9a1d1148d58e129626952219e14ede255 (patch)
treedb2eca2249ccc3230dc6c0a7359986198cab4048 /lib/pure/json.nim
parentdc669155e39007f1b584eef247dff90523f836bf (diff)
downloadNim-4741e8f9a1d1148d58e129626952219e14ede255.tar.gz
ugh, maybe broke git
Diffstat (limited to 'lib/pure/json.nim')
-rwxr-xr-xlib/pure/json.nim14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/pure/json.nim b/lib/pure/json.nim
index 7fbc8bfcf..c90c071b6 100755
--- a/lib/pure/json.nim
+++ b/lib/pure/json.nim
@@ -700,6 +700,18 @@ proc `$`*(node: PJsonNode): String =
   result = ""
   toPretty(result, node, 1, False)
 
+iterator items*(node: PJsonNode): PJSonNode =
+  ## Iterator for the items of `node`. `node` has to be a JArray.
+  assert node.kind == JArray
+  for i in items(node.elems):
+    yield i
+
+iterator pairs*(node: PJsonNode): tuple[key: string, val: PJsonNode] =
+  ## Iterator for the child elements of `node`. `node` has to be a JObject.
+  assert node.kind == JObject
+  for key, val in items(node.fields):
+    yield (key, val)
+
 proc eat(p: var TJsonParser, tok: TTokKind) = 
   if p.tok == tok: discard getTok(p)
   else: raiseParseErr(p, tokToStr[tok])
@@ -711,7 +723,7 @@ proc parseJson(p: var TJsonParser): PJsonNode =
     result = newJString(p.a)
     discard getTok(p)
   of tkInt:
-    result = newJInt(parseInt(p.a))
+    result = newJInt(parseBiggestInt(p.a))
     discard getTok(p)
   of tkFloat:
     result = newJFloat(parseFloat(p.a))