play.api.libs.json

Json

object Json extends JsonFacade

Helper functions to handle JsValues.

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

Type Members

  1. trait DefaultValues extends AnyRef

    Flag to indicate the macros can use the type default values (e.

  2. sealed trait JsValueWrapper extends AnyRef

    Next is the trait that allows Simplified Json syntax :

  3. sealed trait MacroOptions extends AnyRef

    Compile-time base options for macro usage.

  4. type WithDefaultValues = MacroOptions with DefaultValues

    Alias for MacroOptions with DefaultValues

    Alias for MacroOptions with DefaultValues

    Json.using[WithDefaultValues]
  5. final class WithOptions[Opts <: MacroOptions] extends JsonFacade

    JSON facade with some macro options.

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(items: JsValueWrapper*): JsArray

    Returns a JsArray with given items.

    Returns a JsArray with given items.

    Definition Classes
    JsonJsonFacade
  7. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  8. def asciiStringify(json: JsValue): String

    Converts a JsValue to its string representation, escaping all non-ascii characters using \uXXXX syntax.

    Converts a JsValue to its string representation, escaping all non-ascii characters using \uXXXX syntax.

    This is particularly useful when the output JSON will be executed as javascript, since JSON is not a strict subset of javascript (see JSON: The JavaScript subset that isn't).

    scala> Json.asciiStringify(JsString("some\u2028text\u2029"))
    res0: String = "some\u2028text\u2029"
    
    scala> Json.stringify(JsString("some\u2028text\u2029"))
    res1: String = "sometext"
    json

    the JsValue to convert A String with the json representation with all non-ascii characters escaped.

    Definition Classes
    JsonJsonFacade
  9. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  10. def configured[C <: Aux[_ <: MacroOptions]](implicit config: C): WithOptions[_ <: MacroOptions]

    Returns a JsonFacade using the current JSON configuration.

    Returns a JsonFacade using the current JSON configuration.

    C

    the type of compile-time configuration

    // Materializes a `Reads[Foo]`,
    // with the configuration resolved at compile time
    val r: Reads[Foo] = Json.configured.reads[Foo]
  11. final def eq(arg0: AnyRef): Boolean

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

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

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

    Creates a OFormat[T] by resolving, at compile-time, the case class fields or sealed family, and the required implicits.

    Creates a OFormat[T] by resolving, at compile-time, the case class fields or sealed family, and the required implicits.

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

    A

    the type for which the handler must be materialized

    import play.api.libs.json.Json
    
    case class User(userName: 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 = (
       (__ \ implicitly[JsonConfiguration].naming("userName")).format[String] and
       (__ \ implicitly[JsonConfiguration].naming("age")).format[Int]
    )(User.apply, unlift(User.unapply))
    Annotations
    @macroImpl( ... )
  15. def fromJson[T](json: JsValue)(implicit fjs: Reads[T]): JsResult[T]

    Converts a JsValue to a value of requested type T.

    Converts a JsValue to a value of requested type T.

    T

    The type of conversion result, only supported if a Reads implicit is available for.

    json

    the JsValue to convert

    Definition Classes
    JsonJsonFacade
  16. final def getClass(): Class[_]

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

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

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

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

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

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

    Returns a JsObject with given fields.

    Returns a JsObject with given fields.

    fields

    the object fields specified as pairs of name and value

    Definition Classes
    JsonJsonFacade
  23. def parse(input: Array[Byte]): JsValue

    Parses some bytes representing a JSON input, and returns it as a JsValue.

    Parses some bytes representing a JSON input, and returns 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

    the byte array to parse

    Definition Classes
    JsonJsonFacade
  24. def parse(input: InputStream): JsValue

    Parses a stream representing a JSON input, and returns it as a JsValue.

    Parses a stream representing a JSON input, and returns it as a JsValue.

    input

    the InputStream to parse

    Definition Classes
    JsonJsonFacade
  25. def parse(input: String): JsValue

    Parses a String representing a JSON input, and returns it as a JsValue.

    Parses a String representing a JSON input, and returns it as a JsValue.

    input

    the String to parse

    Definition Classes
    JsonJsonFacade
  26. def prettyPrint(json: JsValue): String

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

    Converts a JsValue to its pretty string representation using default 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 A String with the json representation.

    Definition Classes
    JsonJsonFacade
  27. def reads[A]: Reads[A]

    Creates a Reads[T] by resolving, at compile-time, the case class fields or sealed family, and the required implicits.

    Creates a Reads[T] by resolving, at compile-time, the case class fields or sealed family, and the required implicits.

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

    A

    the type for which the handler must be materialized

    import play.api.libs.json.Json
    
    case class User(userName: 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 = (
       (__ \ implicitly[JsonConfiguration].naming("userName")).read[String] and
       (__ \ implicitly[JsonConfiguration].naming("age")).read[Int]
    )(User)
    Annotations
    @macroImpl( ... )
  28. def stringify(json: JsValue): String

    Converts a JsValue to its string representation.

    Converts 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

    Definition Classes
    JsonJsonFacade
  29. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  30. def toBytes(json: JsValue): Array[Byte]

    Converts a JsValue to bytes (using UTF-8 encoding).

    Converts a JsValue to bytes (using UTF-8 encoding).

    json

    the JsValue to convert

    returns

    an Array[Byte] representing the UTF-8-encoded JSON

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

  32. def toJsObject[T](o: T)(implicit tjs: OWrites[T]): JsObject

    Converts any object writeable value to a JsObject.

    Converts any object writeable value to a JsObject.

    A value is writeable as an object, if a OWrites implicit is available for its type.

    T

    the type of the value to be written as JsObject

    o

    the value to convert as JSON object

    Definition Classes
    JsonJsonFacade
  33. def toJson[T](o: T)(implicit tjs: Writes[T]): JsValue

    Converts any writeable value to a JsValue.

    Converts any writeable value to a JsValue.

    A value is writeable if a Writes implicit is available for its type.

    T

    the type of the value to be written as JSON

    o

    the value to convert as JSON

    Definition Classes
    JsonJsonFacade
  34. def toString(): String

    Definition Classes
    AnyRef → Any
  35. def using[Opts <: MacroOptions]: WithOptions[Opts]

    Returns an inference context to call the JSON macros, using explicit compile-time options.

    Returns an inference context to call the JSON macros, using explicit compile-time options.

    Opts

    the compile-time options

  36. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  39. def writes[A]: OWrites[A]

    Creates a OWrites[T] by resolving, at compile-time, the case class fields or sealed family, and the required implicits.

    Creates a OWrites[T] by resolving, at compile-time, the case class fields or sealed family, and the required implicits.

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

    A

    the type for which the handler must be materialized

    import play.api.libs.json.Json
    
    case class User(userName: 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 = (
       (__ \ implicitly[JsonConfiguration].naming("userName")).write[String] and
       (__ \ implicitly[JsonConfiguration].naming("age")).write[Int]
    )(unlift(User.unapply))
    Annotations
    @macroImpl( ... )

Inherited from JsonFacade

Inherited from AnyRef

Inherited from Any

Ungrouped