Merge pull request #3810 from def-/json-speedup
Use tables instead of seqs for json objects
This commit is contained in:
commit
cce64c3357
4 changed files with 49 additions and 48 deletions
|
|
@ -1,13 +1,13 @@
|
|||
|
||||
import json, tables, sequtils
|
||||
|
||||
proc run(json_params: TTable) =
|
||||
proc run(json_params: Table) =
|
||||
let json_elems = json_params["files"].elems
|
||||
# These fail compilation.
|
||||
var files = map(json_elems, proc (x: PJsonNode): string = x.str)
|
||||
#var files = json_elems.map do (x: PJsonNode) -> string: x.str
|
||||
var files = map(json_elems, proc (x: JsonNode): string = x.str)
|
||||
#var files = json_elems.map do (x: JsonNode) -> string: x.str
|
||||
echo "Hey!"
|
||||
|
||||
when isMainModule:
|
||||
let text = """{"files": ["a", "b", "c"]}"""
|
||||
run(toTable((text.parseJson).fields))
|
||||
run((text.parseJson).fields)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ fpqeew
|
|||
[11, 12, 13]
|
||||
[11, 12, 13]
|
||||
[11, 12, 13]
|
||||
{"key1":11,"key2":12,"key3":13}
|
||||
11 12 13
|
||||
[11,12,13]
|
||||
<Students>
|
||||
<Student Name="Aprilfoo" />
|
||||
|
|
@ -115,7 +115,7 @@ block:
|
|||
var j = parseJson """{"key1": 1, "key2": 2, "key3": 3}"""
|
||||
for key,val in j.pairs:
|
||||
val.num += 10
|
||||
echo j
|
||||
echo j["key1"], " ", j["key2"], " ", j["key3"]
|
||||
|
||||
block:
|
||||
var j = parseJson """[1, 2, 3]"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue