Remove varargs from json.{}
This commit is contained in:
parent
be534279da
commit
38cdd7595e
1 changed files with 4 additions and 6 deletions
|
|
@ -713,14 +713,12 @@ proc `[]=`*(obj: PJsonNode, key: string, val: PJsonNode) =
|
||||||
return
|
return
|
||||||
obj.fields.add((key, val))
|
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
|
## Transverses the node and gets the given value. If any of the
|
||||||
## names does not exist, returns nil
|
## names does not exist, returns nil
|
||||||
result = node
|
result = node
|
||||||
for name in names:
|
if isNil(node): return nil
|
||||||
result = result[name]
|
result = result[key]
|
||||||
if isNil(result):
|
|
||||||
return nil
|
|
||||||
|
|
||||||
proc `{}=`*(node: PJsonNode, names: varargs[string], value: PJsonNode) =
|
proc `{}=`*(node: PJsonNode, names: varargs[string], value: PJsonNode) =
|
||||||
## Transverses the node and tries to set the value at the given location
|
## 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" }"""
|
let testJson = parseJson"""{ "a": [1, 2, 3, 4], "b": "asd" }"""
|
||||||
# nil passthrough
|
# nil passthrough
|
||||||
assert(testJson{"doesnt_exist", "anything"} == nil)
|
assert(testJson{"doesnt_exist"}{"anything"}.isNil)
|
||||||
testJson{["c", "d"]} = %true
|
testJson{["c", "d"]} = %true
|
||||||
assert(testJson["c"]["d"].bval)
|
assert(testJson["c"]["d"].bval)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue