play-json icon indicating copy to clipboard operation
play-json copied to clipboard

Add a JSON parsing API that returns Try or similar type instead of throwing exception

Open joelvim opened this issue 4 years ago • 1 comments

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

joelvim avatar Jan 19 '22 11:01 joelvim

Will have a look

cchantep avatar Mar 16 '22 20:03 cchantep