summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@googlemail.com>2014-06-22 20:25:38 +0100
committerDominik Picheta <dominikpicheta@googlemail.com>2014-06-22 20:25:38 +0100
commit38cdd7595eeafe9906c42d258edeacaf50743bb1 (patch)
tree8f0487ed82b2743a57b7fe6339753f28af8b14d6
parentbe534279da5021aa5e6621430a52ee1573f1a01f (diff)
downloadNim-38cdd7595eeafe9906c42d258edeacaf50743bb1.tar.gz
Remove varargs from json.`{}`
-rw-r--r--lib/pure/json.nim10
1 files changed, 4 insertions, 6 deletions
diff --git a/lib/pure/json.nim b/lib/pure/json.nim
index 4e369b854..508e564c5 100644
--- a/lib/pure/json.nim
+++ b/lib/pure/json.nim
@@ -713,14 +713,12 @@ proc `[]=`*(obj: PJsonNode, key: string, val: PJsonNode) =
       return
   obj.fields.add((key, val))
 
-proc `{}`*(node: PJsonNode, names: varargs[string]): PJsonNode =
+proc `{}`*(node: PJsonNode, key: string): PJsonNode =
   ## Transverses the node and gets the given value. If any of the
   ## names does not exist, returns nil
   result = node
-  for name in names:
-    result = result[name]
-    if isNil(result):
-      return nil
+  if isNil(node): return nil
+  result = result[key]
 
 proc `{}=`*(node: PJsonNode, names: varargs[string], value: PJsonNode) =
   ## Transverses the node and tries to set the value at the given location
@@ -1059,7 +1057,7 @@ when isMainModule:
 
   let testJson = parseJson"""{ "a": [1, 2, 3, 4], "b": "asd" }"""
   # nil passthrough
-  assert(testJson{"doesnt_exist", "anything"} == nil)
+  assert(testJson{"doesnt_exist"}{"anything"}.isNil)
   testJson{["c", "d"]} = %true
   assert(testJson["c"]["d"].bval)