play-json
play-json copied to clipboard
Add a JSON parsing API that returns Try or similar type instead of throwing exception
Currently, when JSON.parse processes invalid JSON, it will throw an exception. This is not documented and can be misleading for some users that will forget to catch the exceptions.
It would be ideal to have a new API (not to break compatibility) with a signature like
def tryParse(input: String): Try[JsValue] // or with Either or similar type that encodes error
def tryParse(input: InputStream): Try[JsValue]
def tryParse(input: Array[Byte]): Try[JsValue]
in order to use the type system to prevent user mistakes.
If it is not possible at all to add a new API, at least it would be important to document that exceptions can be thrown.
Play JSON Version
2.9.x
API
Scala
Will have a look