play.api.libs

json

package json

Json API For example:

import play.api.libs.json._
import play.api.libs.functional.syntax._

case class User(id: Long, name: String, friends: Seq[User] = Seq.empty)
object User {

  // In this format, an undefined friends property is mapped to an empty list
  implicit val format: Format[User] = (
    (__ \ "id").format[Long] and
    (__ \ "name").format[String] and
    (__ \ "friends").lazyFormatNullable(implicitly[Format[Seq[User]]])
      .inmap[Seq[User]](_ getOrElse Seq.empty, Some(_))
  )(User.apply, unlift(User.unapply))
}

//then in a controller:

object MyController extends Controller {
   def displayUserAsJson(id: String) = Action {
      Ok(Json.toJson(User(id.toLong, "myName")))
   }
   def saveUser(jsonString: String)= Action {
     val user = Json.parse(jsonString).as[User]
     myDataStore.save(user)
     Ok
   }
}
Source
package.scala
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 LowPriorityDefaultReads

    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.

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

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

  9. case class JsArray(value: Seq[JsValue] = List()) 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. final case class JsDefined(value: JsValue) extends AnyVal with JsLookupResult with Product with Serializable

    Wrapper for JsValue to represent an existing Json value.

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

  13. final case class JsLookup(result: JsLookupResult) extends AnyVal with Product with Serializable

    A value representing the value at a particular JSON path, either an actual JSON node or undefined.

  14. sealed trait JsLookupResult extends JsReadable

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

    Represent a Json number value.

  16. case class JsObject(underlying: Map[String, JsValue]) extends JsValue with Product with Serializable

    Represent a Json object value.

  17. case class JsPath(path: List[PathNode] = List()) extends Product with Serializable

  18. trait JsReadable extends Any

    A trait representing a Json node which can be read as an arbitrary type A using a Reads[A]

  19. sealed trait JsResult[+A] extends AnyRef

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

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

    Represent a Json string value.

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

  23. final class JsUndefined extends JsLookupResult

    Represent a missing Json value.

  24. sealed trait JsValue extends JsReadable

    Generic json value

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

  26. trait LowPriorityDefaultReads extends AnyRef

    Low priority reads.

    Low priority reads.

    This exists as a compiler performance optimisation, so that the compiler doesn't have to rule them out when DefaultReads provides a simple match.

    See https://github.com/playframework/playframework/issues/4313 for more details.

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

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

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

  30. sealed trait PathNode extends AnyRef

  31. trait PathReads extends AnyRef

  32. trait PathWrites extends AnyRef

  33. trait Reads[A] extends AnyRef

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

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

    Annotations
    @implicitNotFound( ... )
  34. case class RecursiveSearch(key: String) extends PathNode with Product with Serializable

  35. trait Writes[-A] extends AnyRef

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

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

    Annotations
    @implicitNotFound( ... )

Value Members

  1. object Format extends PathFormat with ConstraintFormat with DefaultFormat

    Default Json formatters.

  2. object JsError extends Serializable

  3. object JsLookupResult

  4. object JsMacroImpl

  5. object JsNull extends JsValue with Product with Serializable

    Represents a Json null value.

  6. object JsObject extends Serializable

  7. object JsPath extends JsPath

  8. object JsResult

  9. object JsUndefined

  10. object JsValue

  11. object Json

    Helper functions to handle JsValues.

  12. object OFormat

  13. object OWrites extends PathWrites with ConstraintWrites

  14. object Reads extends ConstraintReads with PathReads with DefaultReads

    Default deserializer type classes.

  15. object Writes extends PathWrites with ConstraintWrites with DefaultWrites

    Default Serializers.

  16. val __: JsPath.type

    Alias for JsPath companion object

  17. package jackson

  18. package util

Inherited from AnyRef

Inherited from Any

Ungrouped