diff options
author | Dominik Picheta <dominikpicheta@gmail.com> | 2016-04-05 21:26:26 +0100 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@gmail.com> | 2016-04-05 21:28:53 +0100 |
commit | 3379646c1613c5a29864e5afd350bbf54cdd215c (patch) | |
tree | 83ff6871359584562cac31de6aaa0162229d14a0 /lib/pure | |
parent | 2d80a9e4a6e38e53a7923c9afeeec0f3a9a7aa1d (diff) | |
download | Nim-3379646c1613c5a29864e5afd350bbf54cdd215c.tar.gz |
Add -d:nimJsonGet flag for json.[] and news entry.
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/json.nim | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/pure/json.nim b/lib/pure/json.nim index 5df9de5fa..5be098664 100644 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -56,6 +56,11 @@ import export tables.`$` +when defined(nimJsonGet): + {.pragma: deprecatedGet, deprecated.} +else: + {.pragma: deprecatedGet.} + type JsonEventKind* = enum ## enumeration of all events that may occur when parsing jsonError, ## an error occurred during parsing @@ -799,16 +804,23 @@ proc len*(n: JsonNode): int = of JObject: result = n.fields.len else: discard -proc `[]`*(node: JsonNode, name: string): JsonNode {.inline.} = +proc `[]`*(node: JsonNode, name: string): JsonNode {.inline, deprecatedGet.} = ## Gets a field from a `JObject`, which must not be nil. - ## If the value at `name` does not exist, returns nil + ## If the value at `name` does not exist, raises KeyError. + ## + ## **Note:** The behaviour of this procedure changed in version 0.14.0. To + ## get a list of usages and to restore the old behaviour of this procedure, + ## compile with the ``-d:nimJsonGet`` flag. assert(not isNil(node)) assert(node.kind == JObject) + when defined(nimJsonGet): + if not node.fields.hasKey(name): return nil result = node.fields[name] proc `[]`*(node: JsonNode, index: int): JsonNode {.inline.} = ## Gets the node at `index` in an Array. Result is undefined if `index` - ## is out of bounds + ## is out of bounds, but as long as array bound checks are enabled it will + ## result in an exception. assert(not isNil(node)) assert(node.kind == JArray) return node.elems[index] |