play.api.libs

json

package json

Json API For example:

case class User(id: Long, name: String, friends: List[User])

 implicit object UserFormat extends Format[User] {
  def reads(json: JsValue): User = User(
    (json \ "id").as[Long],
    (json \ "name").as[String],
    (json \ "friends").asOpt[List[User]].getOrElse(List()))
  def writes(u: User): JsValue = JsObject(List(
    "id" -> JsNumber(u.id),
    "name" -> JsString(u.name),
    "friends" -> JsArray(u.friends.map(fr => JsObject(List("id" -> JsNumber(fr.id),
    "name" -> JsString(fr.name)))))))
}

//then in a controller:
object MyController extends Controller {
   def displayUserAsJson(id: String) = Action {
      Ok(toJson( User(id.toLong, "myName", friends: List())))
   }
   def saveUser(jsonString: String)= Action {
     val user = play.api.libs.json.parse(jsonString).as[User]
     myDataStore.save(user)
     Ok
   }
}
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. json
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. trait ConstraintFormat extends AnyRef

  2. trait ConstraintReads extends AnyRef

  3. trait ConstraintWrites extends AnyRef

  4. trait DefaultFormat extends AnyRef

    Default Json formatters.

  5. trait DefaultReads extends AnyRef

    Default deserializer type classes.

  6. trait DefaultWrites extends AnyRef

    Default Serializers.

  7. trait Format[A] extends Writes[A] with Reads[A]

    Json formatter: write an implicit to define both a serializer and a deserializer for any type.

  8. case class IdxPathNode(idx: Int) extends PathNode with Product with Serializable

  9. case class JsArray(value: Seq[JsValue] = immutable.this.Nil) extends JsValue with Product with Serializable

    Represent a Json array value.

  10. case class JsBoolean(value: Boolean) extends JsValue with Product with Serializable

    Represent a Json boolean value.

  11. case class JsError(errors: Seq[(JsPath, Seq[ValidationError])]) extends JsResult[Nothing] with Product with Serializable

  12. case class JsNumber(value: BigDecimal) extends JsValue with Product with Serializable

    Represent a Json number value.

  13. case class JsObject(fields: Seq[(String, JsValue)]) extends JsValue with Product with Serializable

    Represent a Json object value.

  14. case class JsPath(path: List[PathNode] = immutable.this.Nil) extends Product with Serializable

  15. sealed trait JsResult[+A] extends AnyRef

  16. case class JsResultException(errors: Seq[(JsPath, Seq[ValidationError])]) extends RuntimeException with Product with Serializable

  17. case class JsString(value: String) extends JsValue with Product with Serializable

    Represent a Json string value.

  18. case class JsSuccess[T](value: T, path: JsPath = ...) extends JsResult[T] with Product with Serializable

  19. case class JsUndefined(error: String) extends JsValue with Product with Serializable

    Represent a missing Json value.

  20. sealed trait JsValue extends AnyRef

    Generic json value

  21. case class KeyPathNode(key: String) extends PathNode with Product with Serializable

  22. trait OFormat[A] extends OWrites[A] with Reads[A] with Format[A]

  23. trait OWrites[-A] extends Writes[A]

    Annotations
    @implicitNotFound( ... )
  24. trait PathFormat extends AnyRef

  25. sealed trait PathNode extends AnyRef

  26. trait PathReads extends AnyRef

  27. trait PathWrites extends AnyRef

  28. trait Reads[A] extends AnyRef

    Json deserializer: write an implicit to define a deserializer for any type.

  29. case class RecursiveSearch(key: String) extends PathNode with Product with Serializable

  30. trait Writes[-A] extends AnyRef

    Json serializer: write an implicit to define a serializer for any type

Value Members

  1. object Format extends PathFormat with ConstraintFormat with DefaultFormat

    Default Json formatters.

  2. object JsError extends Serializable

  3. object JsMacroImpl

  4. object JsNull extends JsValue with Product with Serializable

    Represent a Json null value.

  5. object JsPath extends JsPath

  6. object JsResult

  7. object Json

    Helper functions to handle JsValues.

  8. object OFormat

  9. object OWrites extends PathWrites with ConstraintWrites

  10. object Reads extends ConstraintReads with PathReads with DefaultReads

    Default deserializer type classes.

  11. object Writes extends PathWrites with ConstraintWrites with DefaultWrites

    Default Serializers.

  12. val __: JsPath.type

    Alias for JsPath companion object

  13. package util

Inherited from AnyRef

Inherited from Any

Ungrouped