Package

play.api.libs

json

Permalink

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
Visibility
  1. Public
  2. All

Type Members

  1. trait ConstraintFormat extends AnyRef

    Permalink
  2. trait ConstraintReads extends AnyRef

    Permalink
  3. trait ConstraintWrites extends AnyRef

    Permalink
  4. trait DefaultFormat extends AnyRef

    Permalink

    Default Json formatters.

  5. trait DefaultReads extends LowPriorityDefaultReads

    Permalink

    Default deserializer type classes.

  6. trait DefaultWrites extends LowPriorityWrites

    Permalink

    Default Serializers.

  7. trait EnvReads extends AnyRef

    Permalink
  8. trait EnvWrites extends AnyRef

    Permalink
  9. trait Format[A] extends Writes[A] with Reads[A]

    Permalink

    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( ... )
  10. case class IdxPathNode(idx: Int) extends PathNode with Product with Serializable

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

    Permalink

    Represent a Json array value.

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

    Permalink

    Represents a Json boolean value.

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

    Permalink

    Wrapper for JsValue to represent an existing Json value.

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

    Permalink

    The result in case of parsing errors.

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

    Permalink

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

  16. sealed trait JsLookupResult extends JsReadable

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

    Permalink

    Represent a Json number value.

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

    Permalink

    Represent a Json object value.

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

    Permalink

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

  20. trait JsReadable extends Any

    Permalink

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

  21. sealed trait JsResult[+A] extends AnyRef

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

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

    Permalink

    Represent a Json string value.

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

    Permalink

    The result for a successful parsing.

  25. final class JsUndefined extends JsLookupResult

    Permalink

    Represent a missing Json value.

  26. sealed trait JsValue extends JsReadable

    Permalink

    Generic json value

  27. sealed trait JsonConfiguration extends AnyRef

    Permalink

    JSON configuration

  28. sealed trait JsonFacade extends AnyRef

    Permalink

  29. trait JsonNaming extends (String) ⇒ String

    Permalink

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

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

    Permalink

    A JSON validation error representation.

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

    Permalink
  32. trait LowPriorityDefaultReads extends EnvReads

    Permalink

    Low priority reads.

    Low priority reads.

    This exists as a compiler performance optimization, 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.

  33. sealed trait LowPriorityWrites extends EnvWrites

    Permalink
  34. trait OFormat[A] extends OWrites[A] with Reads[A] with Format[A]

    Permalink
  35. trait OWrites[-A] extends Writes[A]

    Permalink
    Annotations
    @implicitNotFound( ... )
  36. trait PathFormat extends AnyRef

    Permalink
  37. sealed trait PathNode extends AnyRef

    Permalink
  38. trait PathReads extends AnyRef

    Permalink
  39. trait PathWrites extends AnyRef

    Permalink
  40. trait Reads[A] extends AnyRef

    Permalink

    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( ... )
  41. case class RecursiveSearch(key: String) extends PathNode with Product with Serializable

    Permalink
  42. trait Writes[-A] extends AnyRef

    Permalink

    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

    Permalink

    Default Json formatters.

  2. object JsArray extends (IndexedSeq[JsValue]) ⇒ JsArray with Serializable

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

    Permalink
  4. object JsError extends Serializable

    Permalink
  5. object JsFalse extends JsBoolean with Product with Serializable

    Permalink

    Represents Json Boolean False value.

  6. object JsLookupResult

    Permalink
  7. object JsNull extends JsValue with Product with Serializable

    Permalink

    Represents a Json null value.

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

    Permalink
  9. object JsPath extends JsPath

    Permalink

    Companion object and root path.

    Companion object and root path.

    For an object { "name": "foo" }, the path to the name property is:

    JsPath \ "name"

    For an object { "id": 1, "nested": { "score": 0.12 } }, the path to the nested score is:

    JsPath \ "nested" \ "score"
  10. object JsResult

    Permalink
  11. object JsTrue extends JsBoolean with Product with Serializable

    Permalink

    Represents Json Boolean True value.

  12. object JsUndefined

    Permalink
  13. object JsValue

    Permalink
  14. object Json extends JsonFacade

    Permalink

    Helper functions to handle JsValues.

  15. object JsonConfiguration

    Permalink
  16. object JsonNaming

    Permalink

    Naming companion

  17. object JsonValidationError extends Serializable

    Permalink
  18. object OFormat

    Permalink
  19. object OWrites extends PathWrites with ConstraintWrites

    Permalink
  20. object Reads extends ConstraintReads with PathReads with DefaultReads with GeneratedReads

    Permalink

    Default deserializer type classes.

  21. object StaticBinding

    Permalink
  22. object Writes extends PathWrites with ConstraintWrites with DefaultWrites with GeneratedWrites

    Permalink

    Default Serializers.

  23. val __: JsPath.type

    Permalink

    Alias for JsPath companion object

  24. package jackson

    Permalink
  25. package util

    Permalink

Inherited from AnyRef

Inherited from Any

Ungrouped