play.api.libs.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
}
}
Attributes
Members list
Type members
Classlikes
Parse and serialization settings for BigDecimals. Defines limits that will be used when parsing the BigDecimals, like how many digits are accepted.
Parse and serialization settings for BigDecimals. Defines limits that will be used when parsing the BigDecimals, like how many digits are accepted.
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class BigDecimalParseSettings
Attributes
- Companion
- trait
- Supertypes
-
trait Sumtrait Mirrorclass Objecttrait Matchableclass Any
- Self type
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
Attributes
- Companion
- trait
- Supertypes
-
trait Sumtrait Mirrorclass Objecttrait Matchableclass Any
- Self type
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
object Format.type
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
object Reads.type
Default Json formatters.
Default Json formatters.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
object Format.type
Default deserializer type classes.
Default Serializers.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
object KeyWrites.type
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
Json formatter: write an implicit to define both a serializer and a deserializer for any type.
Default Json formatters.
Default Json formatters.
Attributes
- Companion
- trait
- Supertypes
-
trait DefaultFormattrait ConstraintFormattrait PathFormatclass Objecttrait Matchableclass AnyShow all
- Self type
-
Format.type
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
object Reads.type
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
object Writes.type
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait PathNodeclass Objecttrait Matchableclass AnyShow all
Represent a Json array value.
Represent a Json array value.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait JsValuetrait JsReadableclass Objecttrait Matchableclass AnyShow all
Represents a Json boolean value.
Represents a Json boolean value.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait JsValuetrait JsReadableclass Objecttrait Matchableclass AnyShow all
- Known subtypes
Wrapper for JsValue to represent an existing Json value.
Wrapper for JsValue to represent an existing Json value.
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait JsLookupResulttrait JsReadableclass AnyValtrait Matchableclass AnyShow all
Represents Json Boolean False value.
Represents Json Boolean False value.
Attributes
- Supertypes
-
trait Singletontrait Producttrait Mirrorclass JsBooleantrait Serializabletrait Producttrait Equalstrait JsValuetrait JsReadableclass Objecttrait Matchableclass AnyShow all
- Self type
-
JsFalse.type
A value representing the value at a particular JSON path, either an actual JSON node or undefined.
A value representing the value at a particular JSON path, either an actual JSON node or undefined.
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass AnyValtrait Matchableclass AnyShow all
Attributes
- Companion
- object
- Supertypes
-
trait JsReadableclass Any
- Known subtypes
-
class JsDefinedclass JsUndefined
Attributes
- Companion
- trait
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
JsLookupResult.type
Implementation for the JSON macro.
Implementation for the JSON macro.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
JsMacroImpl.type
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class WithOptions[Opts]
- Self type
-
WithOptions[Opts]
Represents a Json null value.
Represents a Json null value.
Attributes
- Supertypes
-
trait Singletontrait Producttrait Mirrortrait Serializabletrait Producttrait Equalstrait JsValuetrait JsReadableclass Objecttrait Matchableclass AnyShow all
- Self type
-
JsNull.type
Represent a Json number value.
Represent a Json number value.
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait JsValuetrait JsReadableclass Objecttrait Matchableclass AnyShow all
Represent a Json object value.
Represent a Json object value.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait JsValuetrait JsReadableclass Objecttrait Matchableclass AnyShow all
Companion object and root path.
Companion object and root path.
For an object { "name": "foo" }
, the path to the name
property is:
import play.api.libs.json.JsPath
JsPath \ "name"
For an object { "id": 1, "nested": { "score": 0.12 } }
, the path to the nested score
is:
import play.api.libs.json.JsPath
JsPath \ "nested" \ "score"
Attributes
Path to a JsValue; As for path to file on FS, there may not be any matching value in the parsed JSON.
A trait representing a Json node which can be read as an arbitrary type A using a Reads[A]
A trait representing a Json node which can be read as an arbitrary type A using a Reads[A]
Attributes
- Supertypes
-
class Any
- Known subtypes
Attributes
- Supertypes
-
trait Producttrait Equalsclass RuntimeExceptionclass Exceptionclass Throwabletrait Serializableclass Objecttrait Matchableclass AnyShow all
Represent a Json string value.
Represent a Json string value.
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait JsValuetrait JsReadableclass Objecttrait Matchableclass AnyShow all
The result for a successful parsing.
The result for a successful parsing.
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait JsResult[T]class Objecttrait Matchableclass AnyShow all
Represents Json Boolean True value.
Represents Json Boolean True value.
Attributes
- Supertypes
-
trait Singletontrait Producttrait Mirrorclass JsBooleantrait Serializabletrait Producttrait Equalstrait JsValuetrait JsReadableclass Objecttrait Matchableclass AnyShow all
- Self type
-
JsTrue.type
Represent a missing Json value.
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
JsUndefined.type
Helper functions to handle JsValues.
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class JsonParserSettings
Attributes
- Companion
- trait
- Supertypes
-
trait Sumtrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
JsonConfig.type
JSON configuration
Attributes
- Companion
- trait
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
JsonConfiguration.type
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
class WithOptions[Opts]object Json.type
Naming strategy, to map each class property to the corresponding column.
Naming strategy, to map each class property to the corresponding column.
Attributes
- Companion
- object
- Supertypes
-
trait String => Stringclass Objecttrait Matchableclass Any
- Known subtypes
Naming companion
Naming companion
Attributes
- Companion
- trait
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
JsonNaming.type
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
JsonParserSettings.type
A JSON validation error representation.
A JSON validation error representation.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
JsonValidationError.type
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait PathNodeclass Objecttrait Matchableclass AnyShow all
Used to read object key for types other than String
.
Used to read object key for types other than String
.
Attributes
- See also
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
object LanguageTagReads.type
- Self type
-
KeyReads[T]
Attributes
Used to write object key for types other than String
.
Used to write object key for types other than String
.
Attributes
- See also
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
object LanguageTagWrites.type
Attributes
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.
Attributes
- Supertypes
- Known subtypes
-
trait DefaultReadsobject Reads.type
Attributes
- Supertypes
- Known subtypes
-
trait DefaultWritesobject Writes.type
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
MapWrites.type
Attributes
Configure how options should be handled
Configure how options should be handled
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
object Default.typeobject WritesNull.type
OptionHandlers companion
OptionHandlers companion
Attributes
- Companion
- trait
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
OptionHandlers.type
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
object Format.type
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
object Reads.type
A Reads
object describes how to decode JSON into a value. Reads
objects are typically provided as implicit values. When Reads
implicit values are in scope, a program is able to deserialize JSON into values of the right type.
A Reads
object describes how to decode JSON into a value. Reads
objects are typically provided as implicit values. When Reads
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 a Reads
and a Writes
then you get a Format.
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
object ArrayNodeReads.typeobject BigIntReads.typeobject BigIntegerReads.typeobject BooleanReads.typeobject ByteReads.typeobject DoubleReads.typeobject FloatReads.typeobject IntReads.typeobject IsoDateReads.typeobject JsArrayReads.typeobject JsBooleanReads.typeobject JsNumberReads.typeobject JsObjectReads.typeobject JsStringReads.typeobject JsValueReads.typeobject JsonNodeReads.typeobject LongReads.typeobject ObjectNodeReads.typeobject ShortReads.typeobject StringReads.typeclass UUIDReadertrait Format[A]trait OFormat[A]Show all
- Self type
-
Reads[A]
Default deserializer type classes.
Default deserializer type classes.
Attributes
- Companion
- trait
- Supertypes
-
trait GeneratedReadstrait DefaultReadstrait LowPriorityDefaultReadstrait EnvReadstrait PathReadstrait ConstraintReadsclass Objecttrait Matchableclass AnyShow all
- Self type
-
Reads.type
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait PathNodeclass Objecttrait Matchableclass AnyShow all
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
StaticBinding.type
Json serializer: write an implicit to define a serializer for any type
Json serializer: write an implicit to define a serializer for any type
Attributes
- Companion
- object
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
-
object BigDecimalWrites.typeobject BigIntWrites.typeobject BigIntegerWrites.typeobject BooleanWrites.typeobject ByteWrites.typeobject DefaultDateWrites.typeobject DoubleWrites.typeobject FloatWrites.typeobject IntWrites.typeobject JsValueWrites.typeobject JsonNodeWrites.typeobject LongWrites.typeobject ShortWrites.typeobject StringWrites.typeobject UuidWrites.typetrait Format[A]trait OFormat[A]trait OWrites[A]Show all
- Self type
-
Writes[A]
Default Serializers.
Default Serializers.
Attributes
- Companion
- trait
- Supertypes
-
trait GeneratedWritestrait DefaultWritestrait LowPriorityWritestrait EnvWritestrait ConstraintWritestrait PathWritesclass Objecttrait Matchableclass AnyShow all
- Self type
-
Writes.type
Deprecated classlikes
Attributes
- Deprecated
- true
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait BigDecimalParseConfigclass Objecttrait Matchableclass AnyShow all
Attributes
- Deprecated
- true
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- object
- Deprecated
- true
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait JsonConfigclass Objecttrait Matchableclass AnyShow all