Add autovivification example (#7537)

* Add autovivification example

* Update json.nim
This commit is contained in:
Federico Ceratto
2018-04-15 23:02:02 +01:00
committed by Andreas Rumpf
parent 02d6dd723d
commit 93fafc8545

View File

@@ -958,6 +958,11 @@ proc `{}`*(node: JsonNode, keys: varargs[string]): JsonNode =
## Traverses the node and gets the given value. If any of the
## keys do not exist, returns ``nil``. Also returns ``nil`` if one of the
## intermediate data structures is not an object.
## Can be used to create tree structures on the fly (sometimes called `autovivification`:idx:):
##
## .. code-block:: nim
## myjson{"parent", "child", "grandchild"} = newJInt(1)
##
result = node
for key in keys:
if isNil(result) or result.kind != JObject: