Skip to content

Instantly share code, notes, and snippets.

@jpbougie
Created May 21, 2009 16:30
Show Gist options
  • Save jpbougie/115558 to your computer and use it in GitHub Desktop.
Save jpbougie/115558 to your computer and use it in GitHub Desktop.
diff --git a/src/main/scala/dispatch/Json.scala b/src/main/scala/dispatch/Json.scala
index 776da7b..14ef7e9 100644
--- a/src/main/scala/dispatch/Json.scala
+++ b/src/main/scala/dispatch/Json.scala
@@ -123,7 +123,7 @@ object JsValue {
def toJson(x: JsValue): String = x match {
case JsNull => "null"
case JsBoolean(b) => b.toString
- case JsString(s) => "\"" + s + "\""
+ case JsString(s) => "\"" + s.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\\"", "\\\\\"") + "\""
case JsNumber(n) => n.toString
case JsArray(xs) => xs.map(toJson).mkString("[",", ","]")
case JsObject(m) => m.map{case (key, value) => toJson(key) + " : " + toJson(value)}.mkString("{",", ","}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment