diff --git a/std/json.d b/std/json.d index 65adbbe02..61af86a45 100644 --- a/std/json.d +++ b/std/json.d @@ -390,14 +390,14 @@ struct JSONValue } /// Implicitly calls $(D toJSON) on this JSONValue. - string toString() + string toString() const { return toJSON(&this); } /// Implicitly calls $(D toJSON) on this JSONValue, like $(D toString), but /// also passes $(I true) as $(I pretty) argument. - string toPrettyString() + string toPrettyString() const { return toJSON(&this, true); } @@ -1066,6 +1066,13 @@ unittest }`); } +unittest { + auto json = `"hello\nworld"`; + const jv = parseJSON(json); + assert(jv.toString == json); + assert(jv.toPrettyString == json); +} + deprecated unittest { // Bugzilla 12332