diff --git a/json_serialization/writer.nim b/json_serialization/writer.nim index 387abb0..4256771 100644 --- a/json_serialization/writer.nim +++ b/json_serialization/writer.nim @@ -459,6 +459,7 @@ template writeValueStringLike(w, value) = of '\f': addPrefixSlash 'f' # \x0c of '\r': addPrefixSlash 'r' # \x0d of '"' : addPrefixSlash '\"' + of '\\': addPrefixSlash '\\' of '\x00'..'\x07', '\x0b', '\x0e'..'\x1f': s.write "\\u00" s.write hexChars[(uint8(c) shr 4) and 0x0f] diff --git a/tests/test_writer.nim b/tests/test_writer.nim index 5a062ef..0998e86 100644 --- a/tests/test_writer.nim +++ b/tests/test_writer.nim @@ -293,6 +293,7 @@ suite "Test writer": test "escapes": check Json.encode("\x12") == """"\u0012"""" + check Json.encode("""a\b""") == """"a\\b"""" test "Empty object": type NoFields = object