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 } }
- Alphabetic
- By Inheritance
- json
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
sealed
trait
BigDecimalParseConfig extends AnyRef
Parse and serialization settings for BigDecimals.
Parse and serialization settings for BigDecimals. Defines limits that will be used when parsing the BigDecimals, like how many digits are accepted.
- sealed trait BigDecimalSerializerConfig extends AnyRef
- 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 with EnumerationWrites
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( ... )
- trait GeneratedReads extends AnyRef
- trait GeneratedWrites extends AnyRef
- 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
-
class
JsMacroImpl extends AnyRef
Implementation for the JSON macro.
- trait JsMacrosWithOptions[Opts <: MacroOptions] extends JsMacros
-
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 JsonConfig extends AnyRef
-
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
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
Readsobject describes how to decode JSON into a value.A
Readsobject describes how to decode JSON into a value.Readsobjects are typically provided as implicit values. WhenReadsimplicit values are in scope, a program is able to deserialize JSON into values of the right type.The inverse of a
Readsobject is a Writes object, which describes how to encode a value into JSON. If you combine aReadsand aWritesthen 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( ... )
-
final
case class
BigDecimalParseSettings(mathContext: MathContext = MathContext.DECIMAL128, scaleLimit: Int, digitsLimit: Int) extends BigDecimalParseConfig with Product with Serializable
- Annotations
- @deprecated
- Deprecated
(Since version 2.9.4) Use BigDecimalParseConfig instead
-
final
case class
BigDecimalSerializerSettings(minPlain: BigDecimal, maxPlain: BigDecimal) extends BigDecimalSerializerConfig with Product with Serializable
- Annotations
- @deprecated
- Deprecated
(Since version 2.9.4) Use BigDecimalSerializerConfig instead
-
final
case class
JsonParserSettings(bigDecimalParseSettings: BigDecimalParseSettings, bigDecimalSerializerSettings: BigDecimalSerializerSettings, streamReadConstraints: StreamReadConstraints = ...) extends JsonConfig with Product with Serializable
- Annotations
- @deprecated
- Deprecated
(Since version 2.9.4) Use JsonConfig instead
Value Members
-
val
__: JsPath.type
Alias for
JsPathcompanion object - object BigDecimalParseConfig
- object BigDecimalSerializerConfig
-
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 thenameproperty is:import play.api.libs.json.JsPath JsPath \ "name"
For an object
{ "id": 1, "nested": { "score": 0.12 } }, the path to the nestedscoreis: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 with JsMacros with JsValueMacros
Helper functions to handle JsValues.
- object JsonConfig
- object JsonConfiguration
-
object
JsonNaming
Naming companion
- object JsonParserSettings extends Serializable
- object JsonValidationError extends Serializable
- object KeyReads extends EnvKeyReads with LowPriorityKeyReads
- 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.