Fixes problems introduced by #2738. Closes 2755.

This commit is contained in:
Dominik Picheta 2015-05-18 21:57:59 +01:00
commit 59e95c015e

View file

@ -970,15 +970,12 @@ proc toUgly*(result: var string, node: JsonNode) =
for key, value in items(node.fields): for key, value in items(node.fields):
if comma: result.add "," if comma: result.add ","
else: comma = true else: comma = true
result.add "\""
result.add key.escapeJson() result.add key.escapeJson()
result.add "\":" result.add ":"
result.toUgly value result.toUgly value
result.add "}" result.add "}"
of JString: of JString:
result.add "\""
result.add node.str.escapeJson() result.add node.str.escapeJson()
result.add "\""
of JInt: of JInt:
result.add($node.num) result.add($node.num)
of JFloat: of JFloat:
@ -1215,6 +1212,11 @@ when isMainModule:
testJson{["c", "d"]} = %true testJson{["c", "d"]} = %true
assert(testJson["c"]["d"].bval) assert(testJson["c"]["d"].bval)
# test `$`
let stringified = $testJson
let parsedAgain = parseJson(stringified)
assert(parsedAgain["b"].str == "asd")
# Bounds checking # Bounds checking
try: try:
let a = testJson["a"][9] let a = testJson["a"][9]