mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-09 14:32:53 +00:00
* Reorder json `add` and `%`, fixes https://github.com/nim-lang/Nim/issues/6385 * rename json test files
This commit is contained in:
committed by
Dominik Picheta
parent
12af4a3f8a
commit
5b8f33a905
@@ -721,6 +721,16 @@ proc getElems*(n: JsonNode, default: seq[JsonNode] = @[]): seq[JsonNode] =
|
||||
if n.isNil or n.kind != JArray: return default
|
||||
else: return n.elems
|
||||
|
||||
proc add*(father, child: JsonNode) =
|
||||
## Adds `child` to a JArray node `father`.
|
||||
assert father.kind == JArray
|
||||
father.elems.add(child)
|
||||
|
||||
proc add*(obj: JsonNode, key: string, val: JsonNode) =
|
||||
## Sets a field from a `JObject`.
|
||||
assert obj.kind == JObject
|
||||
obj.fields[key] = val
|
||||
|
||||
proc `%`*(s: string): JsonNode =
|
||||
## Generic constructor for JSON data. Creates a new `JString JsonNode`.
|
||||
new(result)
|
||||
@@ -909,16 +919,6 @@ proc contains*(node: JsonNode, val: JsonNode): bool =
|
||||
proc existsKey*(node: JsonNode, key: string): bool {.deprecated.} = node.hasKey(key)
|
||||
## Deprecated for `hasKey`
|
||||
|
||||
proc add*(father, child: JsonNode) =
|
||||
## Adds `child` to a JArray node `father`.
|
||||
assert father.kind == JArray
|
||||
father.elems.add(child)
|
||||
|
||||
proc add*(obj: JsonNode, key: string, val: JsonNode) =
|
||||
## Sets a field from a `JObject`.
|
||||
assert obj.kind == JObject
|
||||
obj.fields[key] = val
|
||||
|
||||
proc `[]=`*(obj: JsonNode, key: string, val: JsonNode) {.inline.} =
|
||||
## Sets a field from a `JObject`.
|
||||
assert(obj.kind == JObject)
|
||||
|
||||
10
tests/stdlib/mjsonexternproc.nim
Normal file
10
tests/stdlib/mjsonexternproc.nim
Normal file
@@ -0,0 +1,10 @@
|
||||
# Test case for https://github.com/nim-lang/Nim/issues/6385
|
||||
|
||||
import json
|
||||
# export json
|
||||
|
||||
proc foo*[T](a: T) =
|
||||
let params = %*{
|
||||
"data": [ 1 ]
|
||||
}
|
||||
echo $params
|
||||
5
tests/stdlib/tjsonexternproc.nim
Normal file
5
tests/stdlib/tjsonexternproc.nim
Normal file
@@ -0,0 +1,5 @@
|
||||
# Test case for https://github.com/nim-lang/Nim/issues/6385
|
||||
|
||||
import mjsonexternproc
|
||||
# import json
|
||||
foo(1)
|
||||
Reference in New Issue
Block a user