Play JSON

Builds Play JSON Reads and Writes out of JSON schema definitions.

API documentation

The JsonSchemas interpreter fixes the JsonSchema[A] type to a type that provides both a Reads[A] and a Writes[A].

Given the following type definition:

sourcesealed trait Shape
case class Circle(radius: Double) extends Shape
case class Rectangle(width: Double, height: Double) extends Shape

Assuming that there is an implicit JsonSchema[Shape] definition, we can encode a Shape into JSON and decode it using the usual Play JSON operations:

sourceimport JsonSchema._
val shape: Shape = Circle(42)
val shapeJson: JsValue = Json.toJson(shape)
val maybeShape: JsResult[Shape] = Json.fromJson[Shape](shapeJson)