Dear all,
I've got a design question, raised by my last response. Currently, if you call `toString` on a `Json` object, it will produce some perfectly valid-looking JSON output, *unless* it happens to be an illegal value, for example:
val bad = json"""{ "foo": "bar" }""".quux
The value `quux` doesn't exist, so `toString` returns `undefined` instead.
But there's never an exception thrown, which means that your application could be printing out invalid JSON (i.e. the word "undefined") without you being immediately aware of it.
The solution is that you should be using the `Json.format(json)` method instead, but you could be forgiven for being unaware of it, and considering `toString` to be sufficient.
I'd like to propose a change to the `toString` method such that rather than outputting ready-to-use JSON, it outputs a Scala representation of that JSON, such that users would be discouraged from using `toString`. Here's what it would look like:
scala> val js = Json(Map("foo" -> "bar"))
js: rapture.json.Json = json"""{"foo":"bar"}"""
or in the event of a failure,
scala> val js = Json(Map("foo" -> "bar")).quux
js: rapture.json.Json = undefined
This would conveniently make the output copy/pastable back into Scala, but it would break code for anyone relying on `toString` for output.
Thoughts, or +1s, anyone?
Cheers,
Jon
--