play.api.libs.json

Json

object Json

Helper functions to handle JsValues.

Source
Json.scala
Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Json
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. sealed trait JsValueWrapper extends NotNull

    Next is the trait that allows Simplified Json syntax :

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. def arr(fields: JsValueWrapper*): JsArray

  7. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  8. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  10. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. def format[A]: Format[A]

    Creates a Format[T] by resolving case class fields & required implicits at COMPILE-time

    Creates a Format[T] by resolving case class fields & required implicits at COMPILE-time

    If any missing implicit is discovered, compiler will break with corresponding error.

    import play.api.libs.json.Json
    
    case class User(name: String, age: Int)
    
    implicit val userWrites = Json.format[User]
    // macro-compiler replaces Json.format[User] by injecting into compile chain
    // the exact code you would write yourself. This is strictly equivalent to:
    implicit val userWrites = (
       (__ \ 'name).format[String] and
       (__ \ 'age).format[Int]
    )(User.apply, unlift(User.unapply))
    Annotations
    @macroImpl( ... )
  13. def fromJson[A](implicit arg0: Reads[A]): Enumeratee[JsValue, A]

    Transform a stream of JsValue to a stream of A, keeping only successful results

    Transform a stream of JsValue to a stream of A, keeping only successful results

    val jsonStream: Enumerator[JsValue] = ???
    val fooStream: Enumerator[Foo] = jsonStream &> Json.fromJson
  14. def fromJson[T](json: JsValue)(implicit fjs: Reads[T]): JsResult[T]

    Provided a Reads implicit for that type is available, convert a JsValue to any type.

    Provided a Reads implicit for that type is available, convert a JsValue to any type.

    json

    Json value to transform as an instance of T.

  15. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  16. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  17. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  18. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  19. final def notify(): Unit

    Definition Classes
    AnyRef
  20. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  21. def obj(fields: (String, JsValueWrapper)*): JsObject

  22. def parse(input: Array[Byte]): JsValue

    Parse a byte array representing a json, and return it as a JsValue.

    Parse a byte array representing a json, and return it as a JsValue.

    The character encoding used will be automatically detected as UTF-8, UTF-16 or UTF-32, as per the heuristics in RFC-4627.

    input

    a byte array to parse

    returns

    the JsValue representing the byte array

  23. def parse(input: String): JsValue

    Parse a String representing a json, and return it as a JsValue.

    Parse a String representing a json, and return it as a JsValue.

    input

    a String to parse

    returns

    the JsValue representing the string

  24. def prettyPrint(json: JsValue): String

    Convert a JsValue to its pretty string representation using default Jackson pretty printer (line feeds after each fields and 2-spaces indentation).

    Convert a JsValue to its pretty string representation using default Jackson pretty printer (line feeds after each fields and 2-spaces indentation).

    scala> Json.stringify(Json.obj(
      "field1" -> Json.obj(
        "field11" -> "value11",
        "field12" -> Json.arr("alpha", 123L)
      )
    ))
    res0: String = {"field1":{"field11":"value11","field12":["alpha",123]}}
    
    scala> Json.prettyPrint(res0)
    res1: String =
    {
      "field1" : {
        "field11" : "value11",
        "field12" : [ "alpha", 123 ]
      }
    }
    json

    the JsValue to convert

    returns

    a String with the json representation

  25. def reads[A]: Reads[A]

    Creates a Reads[T] by resolving case class fields & required implcits at COMPILE-time.

    Creates a Reads[T] by resolving case class fields & required implcits at COMPILE-time.

    If any missing implicit is discovered, compiler will break with corresponding error.

    import play.api.libs.json.Json
    
    case class User(name: String, age: Int)
    
    implicit val userReads = Json.reads[User]
    // macro-compiler replaces Json.reads[User] by injecting into compile chain
    // the exact code you would write yourself. This is strictly equivalent to:
    implicit val userReads = (
       (__ \ 'name).read[String] and
       (__ \ 'age).read[Int]
    )(User)
    Annotations
    @macroImpl( ... )
  26. def stringify(json: JsValue): String

    Convert a JsValue to its string representation.

    Convert a JsValue to its string representation.

    scala> Json.stringify(Json.obj(
      "field1" -> Json.obj(
        "field11" -> "value11",
        "field12" -> Json.arr("alpha", 123L)
      )
    ))
    res0: String = {"field1":{"field11":"value11","field12":["alpha",123]}}
    
    scala> Json.stringify(res0)
    res1: String = {"field1":{"field11":"value11","field12":["alpha",123]}}
    json

    the JsValue to convert

    returns

    a String with the json representation

  27. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  28. implicit def toJsFieldJsValueWrapper[T](field: T)(implicit w: Writes[T]): JsValueWrapper

  29. def toJson[A](implicit arg0: Writes[A]): Enumeratee[A, JsValue]

    Transform a stream of A to a stream of JsValue

    Transform a stream of A to a stream of JsValue

    val fooStream: Enumerator[Foo] = ???
    val jsonStream: Enumerator[JsValue] = fooStream &> Json.toJson
  30. def toJson[T](o: T)(implicit tjs: Writes[T]): JsValue

    Provided a Writes implicit for its type is available, convert any object into a JsValue.

    Provided a Writes implicit for its type is available, convert any object into a JsValue.

    o

    Value to convert in Json.

  31. def toString(): String

    Definition Classes
    AnyRef → Any
  32. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  33. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  34. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  35. def writes[A]: Writes[A]

    Creates a Writes[T] by resolving case class fields & required implcits at COMPILE-time

    Creates a Writes[T] by resolving case class fields & required implcits at COMPILE-time

    If any missing implicit is discovered, compiler will break with corresponding error.

    import play.api.libs.json.Json
    
    case class User(name: String, age: Int)
    
    implicit val userWrites = Json.writes[User]
    // macro-compiler replaces Json.writes[User] by injecting into compile chain
    // the exact code you would write yourself. This is strictly equivalent to:
    implicit val userWrites = (
       (__ \ 'name).write[String] and
       (__ \ 'age).write[Int]
    )(unlift(User.unapply))
    Annotations
    @macroImpl( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped