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

sealed trait BigDecimalParseConfig

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 Object
trait Matchable
class Any
Known subtypes

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Format.type

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Reads.type

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object OWrites.type
object Writes.type

Default Json formatters.

Default Json formatters.

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Format.type

Default deserializer type classes.

Default deserializer type classes.

Attributes

Supertypes
trait EnvReads
class Object
trait Matchable
class Any
Known subtypes
object Reads.type

Default Serializers.

Default Serializers.

Attributes

Supertypes
trait EnvWrites
class Object
trait Matchable
class Any
Known subtypes
object Writes.type
trait EnvKeyReads

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object KeyReads.type
Self type
KeyReads.type
trait EnvKeyWrites

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object KeyWrites.type
trait EnvReads

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait DefaultReads
object Reads.type
trait EnvWrites

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Writes.type
trait Format[A] extends Writes[A], 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.

Attributes

Companion
object
Supertypes
trait Reads[A]
trait Writes[A]
class Object
trait Matchable
class Any
Known subtypes
trait OFormat[A]

Default Json formatters.

Default Json formatters.

Attributes

Companion
trait
Supertypes
trait PathFormat
class Object
trait Matchable
class Any
Show all
Self type
Format.type

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Reads.type

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Writes.type
case class IdxPathNode(idx: Int) extends PathNode

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait PathNode
class Object
trait Matchable
class Any
Show all
case class JsArray(value: IndexedSeq[JsValue]) extends JsValue

Represent a Json array value.

Represent a Json array value.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
trait JsValue
trait JsReadable
class Object
trait Matchable
class Any
Show all
object JsArray extends IndexedSeq[JsValue] => JsArray

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
trait IndexedSeq[JsValue] => JsArray
class Object
trait Matchable
class Any
Show all
Self type
JsArray.type
sealed abstract class JsBoolean(val value: Boolean) extends JsValue, Product, Serializable

Represents a Json boolean value.

Represents a Json boolean value.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
trait JsValue
trait JsReadable
class Object
trait Matchable
class Any
Show all
Known subtypes
object JsFalse.type
object JsTrue.type
object JsBoolean extends Boolean => JsBoolean

Attributes

Companion
class
Supertypes
trait Sum
trait Mirror
trait Boolean => JsBoolean
class Object
trait Matchable
class Any
Show all
Self type
JsBoolean.type
final case class JsDefined(value: JsValue) extends AnyVal, JsLookupResult

Wrapper for JsValue to represent an existing Json value.

Wrapper for JsValue to represent an existing Json value.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait JsReadable
class AnyVal
trait Matchable
class Any
Show all
case class JsError(errors: Seq[(JsPath, Seq[JsonValidationError])]) extends JsResult[Nothing]

The result in case of parsing errors.

The result in case of parsing errors.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
trait JsResult[Nothing]
class Object
trait Matchable
class Any
Show all
object JsError

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
JsError.type
case object JsFalse extends JsBoolean

Represents Json Boolean False value.

Represents Json Boolean False value.

Attributes

Supertypes
trait Singleton
trait Product
trait Mirror
class JsBoolean
trait Serializable
trait Product
trait Equals
trait JsValue
trait JsReadable
class Object
trait Matchable
class Any
Show all
Self type
JsFalse.type
final case class JsLookup(result: JsLookupResult) extends AnyVal

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 Serializable
trait Product
trait Equals
class AnyVal
trait Matchable
class Any
Show all
sealed trait JsLookupResult extends JsReadable

Attributes

Companion
object
Supertypes
trait JsReadable
class Any
Known subtypes
class JsDefined
class JsUndefined

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
object JsMacroImpl

Implementation for the JSON macro.

Implementation for the JSON macro.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class WithOptions[Opts]
Self type
WithOptions[Opts]
case object JsNull extends JsValue

Represents a Json null value.

Represents a Json null value.

Attributes

Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
trait JsValue
trait JsReadable
class Object
trait Matchable
class Any
Show all
Self type
JsNull.type
case class JsNumber(value: BigDecimal) extends JsValue

Represent a Json number value.

Represent a Json number value.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait JsValue
trait JsReadable
class Object
trait Matchable
class Any
Show all
case class JsObject(underlying: Map[String, JsValue]) extends JsValue

Represent a Json object value.

Represent a Json object value.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
trait JsValue
trait JsReadable
class Object
trait Matchable
class Any
Show all
object JsObject extends Seq[(String, JsValue)] => JsObject

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
trait Seq[(String, JsValue)] => JsObject
class Object
trait Matchable
class Any
Show all
Self type
JsObject.type
object JsPath extends JsPath

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

Companion
class
Supertypes
trait Product
trait Mirror
class JsPath
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Self type
JsPath.type
case class JsPath(path: List[PathNode])

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

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

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Known subtypes
object JsPath.type
trait JsReadable

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
class JsDefined
class JsUndefined
trait JsValue
class JsArray
class JsBoolean
object JsFalse.type
object JsTrue.type
object JsNull.type
class JsNumber
class JsObject
class JsString
Show all
sealed trait JsResult[+A]

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class JsError
class JsSuccess[T]
Self type
object JsResult

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
JsResult.type
case class JsResultException(errors: Seq[(JsPath, Seq[JsonValidationError])]) extends RuntimeException

Attributes

Supertypes
trait Product
trait Equals
class RuntimeException
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all
case class JsString(value: String) extends JsValue

Represent a Json string value.

Represent a Json string value.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait JsValue
trait JsReadable
class Object
trait Matchable
class Any
Show all
case class JsSuccess[T](value: T, path: JsPath) extends JsResult[T]

The result for a successful parsing.

The result for a successful parsing.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait JsResult[T]
class Object
trait Matchable
class Any
Show all
case object JsTrue extends JsBoolean

Represents Json Boolean True value.

Represents Json Boolean True value.

Attributes

Supertypes
trait Singleton
trait Product
trait Mirror
class JsBoolean
trait Serializable
trait Product
trait Equals
trait JsValue
trait JsReadable
class Object
trait Matchable
class Any
Show all
Self type
JsTrue.type
final class JsUndefined(err: => String) extends JsLookupResult

Represent a missing Json value.

Represent a missing Json value.

Attributes

Companion
object
Supertypes
trait JsReadable
class Object
trait Matchable
class Any
object JsUndefined

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
sealed trait JsValue extends JsReadable

Generic json value

Generic json value

Attributes

Companion
object
Supertypes
trait JsReadable
class Object
trait Matchable
class Any
Known subtypes
class JsArray
class JsBoolean
object JsFalse.type
object JsTrue.type
object JsNull.type
class JsNumber
class JsObject
class JsString
Show all
object JsValue

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
JsValue.type
object Json extends JsonFacade

Helper functions to handle JsValues.

Helper functions to handle JsValues.

Attributes

Supertypes
trait JsonFacade
class Object
trait Matchable
class Any
Self type
Json.type
sealed trait JsonConfig

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object JsonConfig

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
JsonConfig.type
sealed trait JsonConfiguration

JSON configuration

JSON configuration

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
sealed trait JsonFacade

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
class WithOptions[Opts]
object Json.type
trait JsonNaming extends String => String

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 => String
class Object
trait Matchable
class Any
Known subtypes
object Identity.type
object PascalCase.type
object SnakeCase.type
object JsonNaming

Naming companion

Naming companion

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
JsonNaming.type

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
case class JsonValidationError(messages: Seq[String], args: Any*)

A JSON validation error representation.

A JSON validation error representation.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
case class KeyPathNode(key: String) extends PathNode

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait PathNode
class Object
trait Matchable
class Any
Show all
trait KeyReads[T]

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 Object
trait Matchable
class Any
Known subtypes
object LanguageTagReads.type
Self type
object KeyReads extends EnvKeyReads

Attributes

Companion
trait
Supertypes
trait EnvKeyReads
class Object
trait Matchable
class Any
Self type
KeyReads.type
trait KeyWrites[T]

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 Object
trait Matchable
class Any
Known subtypes
object LanguageTagWrites.type
object KeyWrites extends EnvKeyWrites

Attributes

Companion
trait
Supertypes
trait EnvKeyWrites
class Object
trait Matchable
class Any
Self type
KeyWrites.type

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
trait EnvReads
class Object
trait Matchable
class Any
Known subtypes
trait DefaultReads
object Reads.type
sealed trait LowPriorityWrites extends EnvWrites

Attributes

Supertypes
trait EnvWrites
class Object
trait Matchable
class Any
Known subtypes
object Writes.type
object MapWrites

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
MapWrites.type
trait OFormat[A] extends OWrites[A], Reads[A], Format[A]

Attributes

Companion
object
Supertypes
trait Format[A]
trait Reads[A]
trait OWrites[A]
trait Writes[A]
class Object
trait Matchable
class Any
Show all
object OFormat

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
OFormat.type
trait OWrites[A] extends Writes[A]

Attributes

Companion
object
Supertypes
trait Writes[A]
class Object
trait Matchable
class Any
Known subtypes
trait OFormat[A]

Attributes

Companion
trait
Supertypes
trait PathWrites
class Object
trait Matchable
class Any
Self type
OWrites.type

Configure how options should be handled

Configure how options should be handled

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Default.type
object WritesNull.type

OptionHandlers companion

OptionHandlers companion

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
trait PathFormat

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Format.type
sealed trait PathNode

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait PathReads

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Reads.type
trait PathWrites

Attributes

Supertypes
class Object
trait Matchable
class Any
Known subtypes
object OWrites.type
object Writes.type
trait Reads[A]

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 Object
trait Matchable
class Any
Known subtypes
object ArrayNodeReads.type
object BigIntReads.type
object BigIntegerReads.type
object BooleanReads.type
object ByteReads.type
object DoubleReads.type
object FloatReads.type
object IntReads.type
object IsoDateReads.type
object JsArrayReads.type
object JsBooleanReads.type
object JsNumberReads.type
object JsObjectReads.type
object JsStringReads.type
object JsValueReads.type
object JsonNodeReads.type
object LongReads.type
object ObjectNodeReads.type
object ShortReads.type
object StringReads.type
class UUIDReader
trait Format[A]
trait OFormat[A]
Show all
Self type
Reads[A]

Default deserializer type classes.

Default deserializer type classes.

Attributes

Companion
trait
Supertypes
trait DefaultReads
trait EnvReads
trait PathReads
class Object
trait Matchable
class Any
Show all
Self type
Reads.type
case class RecursiveSearch(key: String) extends PathNode

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
trait PathNode
class Object
trait Matchable
class Any
Show all
object StaticBinding

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
trait Writes[A]

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 Object
trait Matchable
class Any
Known subtypes
object BigDecimalWrites.type
object BigIntWrites.type
object BigIntegerWrites.type
object BooleanWrites.type
object ByteWrites.type
object DefaultDateWrites.type
object DoubleWrites.type
object FloatWrites.type
object IntWrites.type
object JsValueWrites.type
object JsonNodeWrites.type
object LongWrites.type
object ShortWrites.type
object StringWrites.type
object UuidWrites.type
trait Format[A]
trait OFormat[A]
trait OWrites[A]
Show all
Self type
Writes[A]

Default Serializers.

Default Serializers.

Attributes

Companion
trait
Supertypes
trait EnvWrites
trait PathWrites
class Object
trait Matchable
class Any
Show all
Self type
Writes.type

Deprecated classlikes

final case class BigDecimalParseSettings(mathContext: MathContext, scaleLimit: Int, digitsLimit: Int) extends BigDecimalParseConfig

Attributes

Deprecated
true
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class BigDecimalSerializerSettings(minPlain: BigDecimal, maxPlain: BigDecimal) extends BigDecimalSerializerConfig

Attributes

Deprecated
true
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class JsonParserSettings(bigDecimalParseSettings: BigDecimalParseSettings, bigDecimalSerializerSettings: BigDecimalSerializerSettings) extends JsonConfig

Attributes

Companion
object
Deprecated
true
Supertypes
trait Serializable
trait Product
trait Equals
trait JsonConfig
class Object
trait Matchable
class Any
Show all

Value members

Concrete fields

val `__`: JsPath.type

Alias for JsPath companion object

Alias for JsPath companion object

Attributes