mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 18:02:05 +00:00
Add autovivification example (#7537)
* Add autovivification example * Update json.nim
This commit is contained in:
committed by
Andreas Rumpf
parent
02d6dd723d
commit
93fafc8545
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user