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)) } object MyController extends play.api.mvc.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
- Alphabetic
- By Inheritance
- json
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
final
case class
BigDecimalParseSettings(mathContext: MathContext = MathContext.DECIMAL128, scaleLimit: Int, digitsLimit: Int) extends Product with Serializable
Parse settings for BigDecimals.
Parse settings for BigDecimals. Defines limits that will be used when parsing the BigDecimals, like how many digits are accepted.
- mathContext
the MathContext used when parsing.
- scaleLimit
limit the scale, and it is related to the math context used.
- digitsLimit
how many digits are accepted, also related to the math context used.
- final case class BigDecimalSerializerSettings(minPlain: BigDecimal, maxPlain: BigDecimal) extends Product with Serializable
- 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 EnvKeyReads extends AnyRef
- trait EnvKeyWrites extends AnyRef
- 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: IndexedSeq[JsValue] = Array[JsValue]()) 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
-
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.
- final case class JsonParserSettings(bigDecimalParseSettings: BigDecimalParseSettings, bigDecimalSerializerSettings: BigDecimalSerializerSettings) extends Product with Serializable
-
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
KeyReads[T] extends AnyRef
Used to read object key for types other than
String
.Used to read object key for types other than
String
.- See also
-
trait
KeyWrites[T] extends AnyRef
Used to write object key for types other than
String
.Used to write object key for types other than
String
.- See also
-
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
OptionHandlers extends AnyRef
Configure how options should be handled
- trait PathFormat extends AnyRef
- sealed trait PathNode extends AnyRef
- trait PathReads extends AnyRef
- trait PathWrites extends AnyRef
-
trait
Reads[A] extends AnyRef
A
Reads
object describes how to decode JSON into a value.A
Reads
object describes how to decode JSON into a value.Reads
objects are typically provided as implicit values. WhenReads
implicit values are in scope, a program is able to deserialize JSON into values of the right type.The inverse of a
Reads
object is a Writes object, which describes how to encode a value into JSON. If you combine aReads
and aWrites
then you get a Format.- 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 (IndexedSeq[JsValue]) ⇒ JsArray with Serializable
- object JsBoolean extends (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 (Seq[(String, JsValue)]) ⇒ JsObject with 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:import play.api.libs.json.JsPath JsPath \ "name"
For an object
{ "id": 1, "nested": { "score": 0.12 } }
, the path to the nestedscore
is:import play.api.libs.json.JsPath 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 JsonParserSettings extends Serializable
- object JsonValidationError extends Serializable
- object KeyReads extends EnvKeyReads
- object KeyWrites extends EnvKeyWrites
- object MapWrites
- object OFormat
- object OWrites extends PathWrites with ConstraintWrites
-
object
OptionHandlers
OptionHandlers companion
-
object
Reads extends ConstraintReads with PathReads with DefaultReads with GeneratedReads
Default deserializer type classes.
- object StaticBinding
-
object
Writes extends PathWrites with ConstraintWrites with DefaultWrites with GeneratedWrites
Default Serializers.