Object

com.persist

JsonOps

Related Doc: package persist

Permalink

object JsonOps

Provides types and functions for working with Json types.

Json is represented by immutable Scala types. Instead of having separate Json types, type aliases are defined for Json forms.

Scala types used for Json are

- Json Object. Immutable Map[String,Json]. Note that keys are not ordered. When converting to a string with Compact or Pretty keys are sorted. - Json Array. Immutable Seq[Json] - Json String. String - Json Boolean. Boolean - Json Number. Int, Long, BigDecimal (with .), Double (with e) - Json Null. Null

Any of the Json types can be at the top level of a document (not just array and object).

The Json parser supports some extensions that are useful for human edited Json input (such as configurations).

- Comments. The characters // to end of line are discarded during parsing. - Scala-like raw strings. Start with ""{ and end with }"". Treated as normal strings after parsing. - No quotes on simple names. If an object component name starts with a letter and contains only letters and digits the " quotes are not required. After parsing names with and without quotes are not distinguished.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. JsonOps
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Type Members

  1. type Json = Any

    Permalink

    A type alias for all Json forms.

    A type alias for all Json forms. Json values should be restricted by convention to only those types used to represent Json.

  2. type JsonArray = Seq[Json]

    Permalink

    A type alias for Json Arrays.

  3. type JsonObject = Map[String, Json]

    Permalink

    A type alias for of Json Objects.

  4. case class jfield(ilist: Any*) extends Product with Serializable

    Permalink

    An extractor for nested Json values.

    An extractor for nested Json values.

    ilist

    a list of values that are either strings or integers

    • A string selects the value of a JsonObject name-value pair where the name equals the string.
    • An integer i selects the ith elements of a JsonArray.
    Example:
    1. val A = jfield("a")
      val B = jfield("b")
      val C = jfield("c")
      jval match {
        case a:A & b:B => foo(a,b)
        case c:C => bar(c)
      }

Value Members

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

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. object &

    Permalink

    An extractor composition operator.

    An extractor composition operator.

    Example:
    1. val A = jfield("a")
      val B = jfield("b")
      val C = jfield("c")
      jval match {
        case a:A & b:B => foo(a,b)
        case c:C => bar(c)
      }
  4. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  5. def Compact(j: Json, safe: Boolean = false): String

    Permalink

    A Json unparser.

    A Json unparser. It produces the most compact single line string form.

    j

    a Json tree.

    safe

    if false bad data types in tree will throw exceptions; if true no exceptions are thrown and error information is included in the output (default is false).

    returns

    the Json string for the tree.

  6. def Json(s: String): Json

    Permalink

    A Json parser.

    A Json parser.

    s

    a Json string.

    returns

    the Json tree resulting from parsing the string.

  7. def JsonArray(elements: Json*): JsonArray

    Permalink

    A constructor for JsonArray.

    A constructor for JsonArray.

    elements

    a sequence of array element values.

    returns

    the constructed Json Array.

  8. def JsonObject(pairs: (String, Json)*): JsonObject

    Permalink

    A constructor for JsonObject.

    A constructor for JsonObject.

    pairs

    a sequence of name value pairs.

    returns

    the constructed Json Object.

  9. def Pretty(j: Json, indent: Int = 0, width: Int = 50, count: Int = 6, safe: Boolean = false): String

    Permalink

    A Json unparser.

    A Json unparser. It produces a multiple line form designed for human readability.

    j

    a Json tree.

    indent

    the number of characters to indent the entire output (default is 0).

    width

    the maximum number of character that should be on a line (default is 50). This is only a goal; in practice some may contain more characters.

    count

    The maximum number of array elements that should be placed on a single line (default is 6).

    safe

    if false bad data types in tree will throw exceptions; if true no exceptions are thrown and error information is included in the output (default is false).

  10. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  11. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  12. val emptyJsonArray: Seq[Any]

    Permalink

    An empty JsonArray.

  13. val emptyJsonObject: Map[String, Any]

    Permalink

    An empty JsonObject.

  14. final def eq(arg0: AnyRef): Boolean

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

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

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  17. final def getClass(): Class[_]

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

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

    Permalink
    Definition Classes
    Any
  20. def jdelete(a: Json, ilist: Any*): Json

    Permalink

    Delete a value within a nested Json value.

    Delete a value within a nested Json value.

    a

    the input Json value.

    ilist

    a list of values that are either strings or integers

    • A string selects the value of a JsonObject name-value pair where the name equals the string.
    • An integer i selects the ith elements of a JsonArray.
    returns

    a copy of the input with the value replaced.

  21. def jget(a: Json, ilist: Any*): Json

    Permalink

    Get a value within a nested Json value.

    Get a value within a nested Json value.

    a

    the input Json value.

    ilist

    a list of values that are either strings or integers

    • A string selects the value of a JsonObject name-value pair where the name equals the string.
    • An integer i selects the ith elements of a JsonArray.
    returns

    the selected value or null if not present.

  22. def jgetArray(a: Json, ilist: Any*): JsonArray

    Permalink

    Get a JsonArray value within a nested Json value.

    Get a JsonArray value within a nested Json value.

    ilist

    a list of values that are either strings or integers

    • A string selects the value of a JsonObject name-value pair where the name equals the string.
    • An integer i selects the ith elements of a JsonArray.
    returns

    the selected JsonArray value or an empty JsonArray if not present.

  23. def jgetBigDecimal(a: Json, ilist: Any*): BigDecimal

    Permalink

    Get a big decimal value within a nested Json value.

    Get a big decimal value within a nested Json value.

    ilist

    a list of values that are either strings or integers

    • A string selects the value of a JsonObject name-value pair where the name equals the string.
    • An integer i selects the ith elements of a JsonArray.
    returns

    the selected big decimal value or 0.0 if not present.

  24. def jgetBoolean(a: Json, ilist: Any*): Boolean

    Permalink

    Get a boolean value within a nested Json value.

    Get a boolean value within a nested Json value.

    ilist

    a list of values that are either strings or integers

    • A string selects the value of a JsonObject name-value pair where the name equals the string.
    • An integer i selects the ith elements of a JsonArray.
    returns

    the selected boolean value or false if not present.

  25. def jgetDouble(a: Json, ilist: Any*): Double

    Permalink

    Get a double value within a nested Json value.

    Get a double value within a nested Json value.

    ilist

    a list of values that are either strings or integers

    • A string selects the value of a JsonObject name-value pair where the name equals the string.
    • An integer i selects the ith elements of a JsonArray.
    returns

    the selected double value or 0.0 if not present.

  26. def jgetInt(a: Json, ilist: Any*): Int

    Permalink

    Get an integer value within a nested Json value.

    Get an integer value within a nested Json value.

    ilist

    a list of values that are either strings or integers

    • A string selects the value of a JsonObject name-value pair where the name equals the string.
    • An integer i selects the ith elements of a JsonArray.
    returns

    the selected integer value or 0 if not present.

  27. def jgetLong(a: Json, ilist: Any*): Long

    Permalink

    Get a long value within a nested Json value.

    Get a long value within a nested Json value.

    ilist

    a list of values that are either strings or integers

    • A string selects the value of a JsonObject name-value pair where the name equals the string.
    • An integer i selects the ith elements of a JsonArray.
    returns

    the selected long value or 0 if not present.

  28. def jgetObject(a: Json, ilist: Any*): JsonObject

    Permalink

    Get a JsonObject value within a nested Json value.

    Get a JsonObject value within a nested Json value.

    ilist

    a list of values that are either strings or integers

    • A string selects the value of a JsonObject name-value pair where the name equals the string.
    • An integer i selects the ith elements of a JsonArray.
    returns

    the selected JsonObject value or an empty JsonObject if not present.

  29. def jgetString(a: Json, ilist: Any*): String

    Permalink

    Get a string value within a nested Json value.

    Get a string value within a nested Json value.

    ilist

    a list of values that are either strings or integers

    • A string selects the value of a JsonObject name-value pair where the name equals the string.
    • An integer i selects the ith elements of a JsonArray.
    returns

    the selected string value or "" if not present.

  30. def jhas(a: Json, ilist: Any*): Boolean

    Permalink

    Tests if a nested Json value is present.

    Tests if a nested Json value is present.

    a

    the input Json value.

    ilist

    a list of values that are either strings or integers

    • A string selects the value of a JsonObject name-value pair where the name equals the string.
    • An integer i selects the ith elements of a JsonArray.
    returns

    true if the selected field is present.

  31. def jinsert(a: Json, ilist: Any*)(v: Json): Json

    Permalink

    Insert a value within a nested Json value.

    Insert a value within a nested Json value.

    a

    the input Json value.

    ilist

    a list of values that are either strings or integers

    • A string selects the value of a JsonObject name-value pair where the name equals the string.
    • An integer i selects the ith elements of a JsonArray.
    v

    the new value

    returns

    a copy of the input with the value inserted. For JsonArrays the value is inserted before the specified value.

  32. val jnull: Json

    Permalink

    The Json null value.

  33. def jput(a: Json, ilist: Any*)(v: Json): Json

    Permalink

    Replace a value within a nested Json value.

    Replace a value within a nested Json value.

    a

    the input Json value.

    ilist

    a list of values that are either strings or integers

    • A string selects the value of a JsonObject name-value pair where the name equals the string.
    • An integer i selects the ith elements of a JsonArray.
    v

    the new value.

    returns

    a copy of the input with the value replaced.

  34. def jsize(j: Json): Int

    Permalink

    Get the size of a Json value.

    Get the size of a Json value. - For a Json Object the number of name-value pairs. - For a Json Array the number of elements. - For anything else, 0.

  35. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  36. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  37. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  38. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  39. def toString(): String

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

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped