Automatically converting JSON keys to valid symbols.
h3rald h3rald@h3rald.com
Sat, 02 Jun 2018 15:36:59 +0200
2 files changed,
14 insertions(+),
4 deletions(-)
M
core/parser.nim
→
core/parser.nim
@@ -634,9 +634,13 @@ return q
of minDictionary: var d = "{" for i in a.dVal.pairs: - var v = $i.val.val - if (not i.val.quotation): - v = v[1 .. v.len-2] + var v = "" + if i.val.kind == minProcOp: + v = "<compiled>" + else: + v = $i.val.val + if (not i.val.quotation): + v = v[1 .. v.len-2] d = d & v & " :" & $i.key & " " if not a.objType.isNil: d = d & ";" & a.objType
M
core/utils.nim
→
core/utils.nim
@@ -170,7 +170,13 @@ result = json.getStr.newVal
of JObject: var res = newDict(i.scope) for key, value in json.pairs: - discard i.dset(res, key, i.fromJson(value)) + var first = $key[0] + var rest = "" + if key.len > 1: + rest = key[1..key.len-1] + first = sgregex.replace(first, "[^a-zA-Z_]", "_") + rest = sgregex.replace(rest, "[^a-zA-Z0-9/!?+*._-]", "_") + discard i.dset(res, first&rest, i.fromJson(value)) return res of JArray: var res = newSeq[MinValue](0)