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
   }
}
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 LowPriorityWrites

    Default Serializers.

  7. trait EnvReads extends AnyRef

  8. trait EnvWrites extends AnyRef

  9. 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.

  10. trait GeneratedReads extends AnyRef

  11. trait GeneratedWrites extends AnyRef

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

  13. case class JsArray(value: IndexedSeq[JsValue] = ...) extends JsValue with Product with Serializable

    Represent a Json array value.

  14. sealed abstract class JsBoolean extends JsValue with Product with Serializable

    Represents a Json boolean value.

  15. final case class JsDefined(value: JsValue) extends AnyVal with JsLookupResult with Product with Serializable

    Wrapper for JsValue to represent an existing Json value.

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

    The result in case of parsing errors.

  17. 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.

  18. sealed trait JsLookupResult extends JsReadable

  19. class JsMacroImpl extends AnyRef

    Implementation for the JSON macro.

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

    Represent a Json number value.

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

    Represent a Json object value.

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

    Path to a JsValue; As for path to file on FS, there may not be any matching value in the parsed JSON.

  23. trait JsReadable extends Any

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

  24. sealed trait JsResult[+A] extends AnyRef

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

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

    Represent a Json string value.

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

    The result for a successful parsing.

  28. final class JsUndefined extends JsLookupResult

    Represent a missing Json value.

  29. sealed trait JsValue extends JsReadable

    Generic json value

  30. sealed trait JsonConfiguration extends AnyRef

    JSON configuration

  31. sealed trait JsonFacade extends AnyRef

  32. trait JsonNaming extends (String) ⇒ String

    Naming strategy, to map each class property to the corresponding column.

  33. case class JsonValidationError(messages: Seq[String], args: Any*) extends Product with Serializable

    A JSON validation error representation.

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

  35. trait LowPriorityDefaultReads extends EnvReads

    Low priority reads.

  36. sealed trait LowPriorityWrites extends EnvWrites

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

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

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

  40. sealed trait PathNode extends AnyRef

  41. trait PathReads extends AnyRef

  42. trait PathWrites extends AnyRef

  43. trait Reads[A] extends AnyRef

    A Reads object describes how to decode JSON into a value.

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

  45. 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 JsArray extends (IndexedSeq[JsValue]) ⇒ JsArray with Serializable

  3. object JsBoolean extends (Boolean) ⇒ JsBoolean with Serializable

  4. object JsError extends Serializable

  5. object JsFalse extends JsBoolean with Product with Serializable

    Represents Json Boolean False value.

  6. object JsLookupResult

  7. object JsMacroImpl

  8. object JsNull extends JsValue with Product with Serializable

    Represents a Json null value.

  9. object JsObject extends (Seq[(String, JsValue)]) ⇒ JsObject with Serializable

  10. object JsPath extends JsPath

    Companion object and root path.

  11. object JsResult

  12. object JsTrue extends JsBoolean with Product with Serializable

    Represents Json Boolean True value.

  13. object JsUndefined

  14. object JsValue

  15. object Json extends JsonFacade

    Helper functions to handle JsValues.

  16. object JsonConfiguration

  17. object JsonNaming

    Naming companion

  18. object JsonValidationError extends Serializable

  19. object OFormat

  20. object OWrites extends PathWrites with ConstraintWrites

  21. object Reads extends ConstraintReads with PathReads with DefaultReads with GeneratedReads

    Default deserializer type classes.

  22. object StaticBinding

  23. object Writes extends PathWrites with ConstraintWrites with DefaultWrites with GeneratedWrites

    Default Serializers.

  24. val __: JsPath.type

    Alias for JsPath companion object

  25. package jackson

  26. package util

Inherited from AnyRef

Inherited from Any

Ungrouped