diff options
author | def <dennis@felsin9.de> | 2016-03-04 19:16:49 +0100 |
---|---|---|
committer | def <dennis@felsin9.de> | 2016-03-04 19:16:49 +0100 |
commit | 0179d842dc90bff400dcabbb28cfe46ebdf1ed98 (patch) | |
tree | 259096d309bcca20e99f57f224459e8820d1c670 /lib/pure | |
parent | 180a4b7657260af5411a4bea58240d3cac2ea0fe (diff) | |
download | Nim-0179d842dc90bff400dcabbb28cfe46ebdf1ed98.tar.gz |
Support json null in %*
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/json.nim | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/pure/json.nim b/lib/pure/json.nim index c5b1a21e9..0d000e05f 100644 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -628,6 +628,9 @@ proc newJArray*(): JsonNode = result.kind = JArray result.elems = @[] +const + null*: string = nil ## alias for ``nil`` + proc getStr*(n: JsonNode, default: string = ""): string = ## Retrieves the string value of a `JString JsonNode`. ## @@ -678,6 +681,7 @@ proc getElems*(n: JsonNode, default: seq[JsonNode] = @[]): seq[JsonNode] = proc `%`*(s: string): JsonNode = ## Generic constructor for JSON data. Creates a new `JString JsonNode`. new(result) + if s.isNil: return result.kind = JString result.str = s @@ -1310,3 +1314,6 @@ when isMainModule: } ] doAssert j3 == %[%{"name": %"John", "age": %30}, %{"name": %"Susan", "age": %31}] + + var j4 = %*{"test": null} + doAssert j4 == %{"test": newJNull()} |