diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2016-06-17 14:12:25 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-17 14:12:25 +0100 |
commit | b0e4c0ae26373edbeb73ae91a959ed460cc810b0 (patch) | |
tree | 4afc55a0ac517425760e7796b77f49d5c8cc9495 /lib | |
parent | 494b3b39177749a4e6b7c52e463a2a219ab46542 (diff) | |
parent | d913ec168574f889ba3c59d88f44f60c5b4d6e9b (diff) | |
download | Nim-b0e4c0ae26373edbeb73ae91a959ed460cc810b0.tar.gz |
Merge pull request #4357 from SSPkrolik/json-contains
Implemented `in` operator support for JsonNode objects
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/json.nim | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/pure/json.nim b/lib/pure/json.nim index e99a351a1..b4eecdf88 100644 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -848,6 +848,16 @@ proc hasKey*(node: JsonNode, key: string): bool = assert(node.kind == JObject) result = node.fields.hasKey(key) +proc contains*(node: JsonNode, key: string): bool = + ## Checks if `key` exists in `node`. + assert(node.kind == JObject) + node.fields.hasKey(key) + +proc contains*(node: JsonNode, val: JsonNode): bool = + ## Checks if `val` exists in array `node`. + assert(node.kind == JArray) + find(node.elems, val) >= 0 + proc existsKey*(node: JsonNode, key: string): bool {.deprecated.} = node.hasKey(key) ## Deprecated for `hasKey` |