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 } }
- Alphabetic
- By Inheritance
- json
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
- trait ConstraintFormat extends AnyRef
- trait ConstraintReads extends AnyRef
- trait ConstraintWrites extends AnyRef
-
trait
DefaultFormat
extends AnyRef
Default Json formatters.
-
trait
DefaultReads
extends LowPriorityDefaultReads
Default deserializer type classes.
-
trait
DefaultWrites
extends LowPriorityWrites
Default Serializers.
- trait EnvReads extends AnyRef
- trait EnvWrites extends AnyRef
-
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( ... )
- case class IdxPathNode (idx: Int) extends PathNode with Product with Serializable
-
case class
JsArray
(value: Seq[JsValue] = List()) extends JsValue with Product with Serializable
Represent a Json array value.
-
sealed abstract
class
JsBoolean
extends JsValue with Product with Serializable
Represents a Json boolean value.
-
final
case class
JsDefined
(value: JsValue) extends AnyVal with JsLookupResult with Product with Serializable
Wrapper for JsValue to represent an existing Json value.
-
case class
JsError
(errors: Seq[(JsPath, Seq[JsonValidationError])]) extends JsResult[Nothing] with Product with Serializable
The result in case of parsing
errors
. -
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.
- sealed trait JsLookupResult extends JsReadable
-
class
JsMacroImpl
extends AnyRef
Implementation for the JSON macro.
-
case class
JsNumber
(value: BigDecimal) extends JsValue with Product with Serializable
Represent a Json number value.
-
case class
JsObject
(underlying: Map[String, JsValue]) extends JsValue with Product with Serializable
Represent a Json object value.
-
case class
JsPath
(path: List[PathNode] = List()) 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.
-
trait
JsReadable
extends Any
A trait representing a Json node which can be read as an arbitrary type A using a Reads[A]
- sealed trait JsResult [+A] extends AnyRef
- case class JsResultException (errors: Seq[(JsPath, Seq[JsonValidationError])]) extends RuntimeException with Product with Serializable
-
case class
JsString
(value: String) extends JsValue with Product with Serializable
Represent a Json string value.
-
case class
JsSuccess
[T](value: T, path: JsPath = JsPath()) extends JsResult[T] with Product with Serializable
The result for a successful parsing.
-
final
class
JsUndefined
extends JsLookupResult
Represent a missing Json value.
-
sealed
trait
JsValue
extends JsReadable
Generic json value
-
sealed
trait
JsonConfiguration
extends AnyRef
JSON configuration
- sealed trait JsonFacade extends AnyRef
-
trait
JsonNaming
extends (String) ⇒ String
Naming strategy, to map each class property to the corresponding column.
-
case class
JsonValidationError
(messages: Seq[String], args: Any*) extends Product with Serializable
A JSON validation error representation.
- case class KeyPathNode (key: String) extends PathNode with Product with Serializable
-
trait
LowPriorityDefaultReads
extends EnvReads
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.
- sealed trait LowPriorityWrites extends EnvWrites
- trait OFormat [A] extends OWrites[A] with Reads[A] with Format[A]
-
trait
OWrites
[-A] extends Writes[A]
- Annotations
- @implicitNotFound( ... )
- trait PathFormat extends AnyRef
- sealed trait PathNode extends AnyRef
- trait PathReads extends AnyRef
- trait PathWrites extends AnyRef
-
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( ... )
- case class RecursiveSearch (key: String) extends PathNode with Product with Serializable
-
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
-
val
__: JsPath.type
Alias for
JsPath
companion object -
object
Format
extends PathFormat with ConstraintFormat with DefaultFormat
Default Json formatters.
- object JsArray extends Serializable
- object JsBoolean extends AbstractFunction1[Boolean, JsBoolean] with Serializable
- object JsError extends Serializable
-
object
JsFalse
extends JsBoolean with Product with Serializable
Represents Json Boolean False value.
- object JsLookupResult
-
object
JsNull
extends JsValue with Product with Serializable
Represents a Json null value.
- object JsObject extends Serializable
-
object
JsPath
extends JsPath
Companion object and root path.
Companion object and root path.
For an object
{ "name": "foo" }
, the path to thename
property is:JsPath \ "name"
For an object
{ "id": 1, "nested": { "score": 0.12 } }
, the path to the nestedscore
is:JsPath \ "nested" \ "score"
- object JsResult
-
object
JsTrue
extends JsBoolean with Product with Serializable
Represents Json Boolean True value.
- object JsUndefined
- object JsValue
-
object
Json
extends JsonFacade
Helper functions to handle JsValues.
- object JsonConfiguration
-
object
JsonNaming
Naming companion
- object JsonValidationError extends Serializable
- object OFormat
- object OWrites extends PathWrites with ConstraintWrites
-
object
Reads
extends ConstraintReads with PathReads with DefaultReads
Default deserializer type classes.
- object StaticBinding
-
object
Writes
extends PathWrites with ConstraintWrites with DefaultWrites
Default Serializers.