Packages

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
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. json
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Package Members

  1. package jackson
  2. package util

Type Members

  1. 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.

  2. sealed trait BigDecimalSerializerConfig extends AnyRef
  3. trait ConstraintFormat extends AnyRef
  4. trait ConstraintReads extends AnyRef
  5. trait ConstraintWrites extends AnyRef
  6. trait DefaultFormat extends AnyRef

    Default Json formatters.

  7. trait DefaultReads extends LowPriorityDefaultReads

    Default deserializer type classes.

  8. trait DefaultWrites extends LowPriorityWrites with EnumerationWrites

    Default Serializers.

  9. trait EnvKeyReads extends AnyRef
  10. trait EnvKeyWrites extends AnyRef
  11. trait EnvReads extends AnyRef
  12. trait EnvWrites extends AnyRef
  13. 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()
  14. trait GeneratedReads extends AnyRef
  15. trait GeneratedWrites extends AnyRef
  16. case class IdxPathNode(idx: Int) extends PathNode with Product with Serializable
  17. case class JsArray(value: IndexedSeq[JsValue] = Array[JsValue]()) extends JsValue with Product with Serializable

    Represent a Json array value.

  18. sealed abstract class JsBoolean extends JsValue with Product with Serializable

    Represents a Json boolean value.

  19. final case class JsDefined(value: JsValue) extends AnyVal with JsLookupResult with Product with Serializable

    Wrapper for JsValue to represent an existing Json value.

  20. case class JsError(errors: Seq[(JsPath, Seq[JsonValidationError])]) extends JsResult[Nothing] with Product with Serializable

    The result in case of parsing errors.

  21. 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.

  22. sealed trait JsLookupResult extends JsReadable
  23. trait JsMacrosWithOptions[Opts <: MacroOptions] extends JsMacros
  24. case class JsNumber(value: BigDecimal) extends JsValue with Product with Serializable

    Represent a Json number value.

  25. case class JsObject(underlying: Map[String, JsValue]) extends JsValue with Product with Serializable

    Represent a Json object value.

  26. 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.

  27. trait JsReadable extends Any

    A trait representing a Json node which can be read as an arbitrary type A using a Reads[A]

  28. sealed trait JsResult[+A] extends AnyRef
  29. case class JsResultException(errors: Seq[(JsPath, Seq[JsonValidationError])]) extends RuntimeException with Product with Serializable
  30. case class JsString(value: String) extends JsValue with Product with Serializable

    Represent a Json string value.

  31. case class JsSuccess[T](value: T, path: JsPath = JsPath()) extends JsResult[T] with Product with Serializable

    The result for a successful parsing.

  32. final class JsUndefined extends JsLookupResult

    Represent a missing Json value.

  33. sealed trait JsValue extends JsReadable

    Generic json value

  34. sealed trait JsonConfig extends AnyRef
  35. sealed trait JsonConfiguration extends AnyRef

    JSON configuration

  36. sealed trait JsonFacade extends AnyRef

  37. trait JsonNaming extends (String) => String

    Naming strategy, to map each class property to the corresponding column.

  38. case class JsonValidationError(messages: Seq[String], args: Any*) extends Product with Serializable

    A JSON validation error representation.

  39. case class KeyPathNode(key: String) extends PathNode with Product with Serializable
  40. 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

    Reads.keyMapReads

  41. 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

    Writes.keyMapWrites

  42. 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.

  43. sealed trait LowPriorityWrites extends EnvWrites
  44. trait OFormat[A] extends OWrites[A] with Reads[A] with Format[A]
  45. trait OWrites[A] extends Writes[A]
    Annotations
    @implicitNotFound()
  46. trait OptionHandlers extends AnyRef

    Configure how options should be handled

  47. trait PathFormat extends AnyRef
  48. sealed trait PathNode extends AnyRef
  49. trait PathReads extends AnyRef
  50. trait PathWrites extends AnyRef
  51. 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. 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.

    Annotations
    @implicitNotFound()
  52. case class RecursiveSearch(key: String) extends PathNode with Product with Serializable
  53. 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()

Deprecated Type Members

  1. 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

  2. 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

  3. final case class JsonParserSettings(bigDecimalParseSettings: BigDecimalParseSettings, bigDecimalSerializerSettings: BigDecimalSerializerSettings) extends JsonConfig with Product with Serializable
    Annotations
    @deprecated
    Deprecated

    (Since version 2.9.4) Use JsonConfig instead

Value Members

  1. val __: JsPath.type

    Alias for JsPath companion object

  2. object BigDecimalParseConfig
  3. object BigDecimalSerializerConfig
  4. object Format extends PathFormat with ConstraintFormat with DefaultFormat

    Default Json formatters.

  5. object JsArray extends (IndexedSeq[JsValue]) => JsArray with Serializable
  6. object JsBoolean extends (Boolean) => JsBoolean with Serializable
  7. object JsError extends Serializable
  8. case object JsFalse extends JsBoolean with Product with Serializable

    Represents Json Boolean False value.

  9. object JsLookupResult
  10. case object JsNull extends JsValue with Product with Serializable

    Represents a Json null value.

  11. object JsObject extends (Seq[(String, JsValue)]) => JsObject with Serializable
  12. 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"
  13. object JsResult
  14. case object JsTrue extends JsBoolean with Product with Serializable

    Represents Json Boolean True value.

  15. object JsUndefined
  16. object JsValue
  17. object Json extends JsonFacade with JsMacros with JsValueMacros

    Helper functions to handle JsValues.

  18. object JsonConfig
  19. object JsonConfiguration
  20. object JsonNaming

    Naming companion

  21. object JsonParserSettings extends Serializable
  22. object JsonValidationError extends Serializable
  23. object KeyReads extends EnvKeyReads with LowPriorityKeyReads
  24. object KeyWrites extends EnvKeyWrites
  25. object MapWrites
  26. object OFormat
  27. object OWrites extends PathWrites with ConstraintWrites
  28. object OptionHandlers

    OptionHandlers companion

  29. object Reads extends ConstraintReads with PathReads with DefaultReads with GeneratedReads

    Default deserializer type classes.

  30. object StaticBinding
  31. object Writes extends PathWrites with ConstraintWrites with DefaultWrites with GeneratedWrites

    Default Serializers.

Inherited from AnyRef

Inherited from Any

Ungrouped