timotheecour / Nim

Nim is a compiled, garbage-collected systems programming language with a design that focuses on efficiency, expressiveness, and elegance (in that order of priority).
http://nim-lang.org/
Other
2 stars 0 forks source link

fromJsonStr, addJsonStr: use JsonParser directly, no intermediate JsonNode #745

Open timotheecour opened 3 years ago

timotheecour commented 3 years ago

refs https://forum.nim-lang.org/t/8074#51665

JSON.parse(json_str) already gets you a js object on which to operate, whereas in json or jsonutils you have an intermediate JsonNode representation:

parseJson(json_str).jsonTo(OptionChain)

what's missing is (in jsonutils):

proc fromJsonStr[T](a: var T, b: string)
proc addJsonStr[T](result: var string, a: T)

from which you can derive outplace procs if needed (jsonStrTo, and toJsonStr)

this should have no overhead

note

there's a question on whether this should use streams, and JsonParser directly

see also parseJsonFragment