Using Writes converters

Scala to JsValue conversion is performed by the utility method Json.toJson[T](T)(implicit writes: Writes[T]). This functionality depends on a converter of type Writes[T] which can convert a T to a JsValue.

The Play JSON API provides implicit Writes for most basic types, such as Int, Double, String, and Boolean. It also supports Writes for collections of any type T that a Writes[T] exists.

Using JsValue.as/asOpt

The simplest way to convert a JsValue to another type is using JsValue.as[T](implicit fjs: Reads[T]): T. This requires an implicit converter of type Reads[T] to convert a JsValue to T (the inverse of Writes[T]). As with Writes, the JSON API provides Reads for basic types.

Using validation

The preferred way to convert from a JsValue to another type is by using its validate method (which takes an argument of type Reads). This performs both validation and conversion, returning a type of JsResult. JsResult is implemented by two classes:

JsSuccess - Represents a successful validation/conversion and wraps the result.