JsonValue

sealed trait JsonValue

Defines JSON value.

class Object
trait Matchable
class Any
object JsonFalse.type
object JsonTrue.type
trait JsonNull
object JsonNull.type
trait JsonArray

Value members

Abstract methods

@targetName("updated")
def +(field: (String, JsonValue)): JsonObject
Implicitly added by toJsonObjectConversion

Adds or updates field.

Adds or updates field.

Returns:

new JSON object

@targetName("concat")
def ++(suffix: JsonArray): JsonArray
Implicitly added by toJsonArrayConversion

Concatenates JSON array.

Concatenates JSON array.

Returns:

new JSON array

@targetName("concat")
def ++(other: JsonObject): JsonObject
Implicitly added by toJsonObjectConversion

Concatenates JSON object.

Concatenates JSON object.

Returns:

new JSON object

@targetName("prepend")
def +:(value: JsonValue): JsonArray
Implicitly added by toJsonArrayConversion

Prepends value.

Prepends value.

Returns:

new JSON array

@targetName("removed")
def -(name: String): JsonObject
Implicitly added by toJsonObjectConversion

Removes field.

Removes field.

Value parameters:
name

field name

Returns:

new JSON object

@targetName("append")
def :+(value: JsonValue): JsonArray
Implicitly added by toJsonArrayConversion

Appends value.

Appends value.

Returns:

new JSON array

def apply(index: Int): JsonValue
Implicitly added by toJsonArrayConversion

Gets value at given index.

Gets value at given index.

def apply(name: String): JsonValue
Implicitly added by toJsonObjectConversion

Gets value.

Gets value.

Value parameters:
name

field name

def fields: Map[String, JsonValue]
Implicitly added by toJsonObjectConversion

Gets fields.

Gets fields.

def get(name: String): Option[JsonValue]
Implicitly added by toJsonObjectConversion

Gets optional value.

Gets optional value.

Value parameters:
name

field name

Implicitly added by toJsonArrayConversion

Selects first value in array.

Selects first value in array.

Throws:
NoSuchElementException

if array is empty

def headOption: Option[JsonValue]
Implicitly added by toJsonArrayConversion

Optionally selects first value in array.

Optionally selects first value in array.

Implicitly added by toJsonArrayConversion

Selects all values in array excluding last.

Selects all values in array excluding last.

Throws:
UnsupportedOperationException

if array is empty

Implicitly added by toJsonArrayConversion

Selects last value in array.

Selects last value in array.

Throws:
NoSuchElementException

if array is empty

def lastOption: Option[JsonValue]
Implicitly added by toJsonArrayConversion

Optionally selects last value in array.

Optionally selects last value in array.

def names: Seq[String]
Implicitly added by toJsonObjectConversion

Gets field names.

Gets field names.

def slice(from: Int, until: Int): JsonArray
Implicitly added by toJsonArrayConversion

Selects slice of array.

Selects slice of array.

Value parameters:
from

lowest index to include

until

lowest index to exclude

Returns:

slice of JSON array containing elements whose indexes are greater than or equal to from and less than until

Implicitly added by toJsonArrayConversion

Selects all values in array excluding first.

Selects all values in array excluding first.

Throws:
UnsupportedOperationException

if array is empty

def updated(index: Int, value: JsonValue): JsonArray
Implicitly added by toJsonArrayConversion

Updates value at given index.

Updates value at given index.

Returns:

new JSON array

def values: Seq[JsonValue]
Implicitly added by toJsonArrayConversion

Gets values.

Gets values.

Concrete methods

@targetName("at")
Extension method from grapple.json

Gets value in JSON object.

Gets value in JSON object.

Value parameters:
name

field name

Throws:
ClassCastException

if not JsonObject

@targetName("at")
Extension method from grapple.json

Gets value in JSON array.

Gets value in JSON array.

Value parameters:
index

array index

Throws:
ClassCastException

if not JsonArray

@targetName("collect")
def \\: Seq[JsonValue]
Extension method from grapple.json

Collects values with given field name while traversing nested objects and arrays.

Collects values with given field name while traversing nested objects and arrays.

import grapple.json.{ Json, \\, given }

val json = Json.parse("""{
 "node": {
   "name": "localhost",
   "users": [
     { "id": 0,    "name": "root" },
     { "id": 1000, "name": "lupita"  }
   ]
 }
}""")

val names = (json \\ "name").map(_.as[String])

assert { names == Seq("localhost", "root", "lupita") }
Value parameters:
name

field name

final def as[T](using converter: JsonInput[T]): T

Converts value.

Converts value.

def getBigDecimal(index: Int): BigDecimal
Implicitly added by toJsonArrayConversion

Gets BigDecimal at given index.

Gets BigDecimal at given index.

Throws:
ClassCastException

if not JsonNumber

def getBigDecimal(name: String): BigDecimal
Implicitly added by toJsonObjectConversion

Gets BigDecimal.

Gets BigDecimal.

Value parameters:
name

field name

Throws:
ClassCastException

if not JsonNumber

def getBigInt(index: Int): BigInt
Implicitly added by toJsonArrayConversion

Gets BigInt at given index.

Gets BigInt at given index.

Throws:
ClassCastException

if not JsonNumber

def getBigInt(name: String): BigInt
Implicitly added by toJsonObjectConversion

Gets BigInt.

Gets BigInt.

Value parameters:
name

field name

Throws:
ClassCastException

if not JsonNumber

def getBoolean(index: Int): Boolean
Implicitly added by toJsonArrayConversion

Gets Boolean at given index.

Gets Boolean at given index.

Throws:
ClassCastException

if not JsonBoolean

def getBoolean(name: String): Boolean
Implicitly added by toJsonObjectConversion

Gets Boolean.

Gets Boolean.

Value parameters:
name

field name

Throws:
ClassCastException

if not JsonBoolean

def getByte(index: Int): Byte
Implicitly added by toJsonArrayConversion

Gets Byte at given index.

Gets Byte at given index.

Throws:
ClassCastException

if not JsonNumber

def getByte(name: String): Byte
Implicitly added by toJsonObjectConversion

Gets Byte.

Gets Byte.

Value parameters:
name

field name

Throws:
ClassCastException

if not JsonNumber

def getDouble(index: Int): Double
Implicitly added by toJsonArrayConversion

Gets Double at given index.

Gets Double at given index.

Throws:
ClassCastException

if not JsonNumber

def getDouble(name: String): Double
Implicitly added by toJsonObjectConversion

Gets Double.

Gets Double.

Value parameters:
name

field name

Throws:
ClassCastException

if not JsonNumber

def getFloat(index: Int): Float
Implicitly added by toJsonArrayConversion

Gets Float at given index.

Gets Float at given index.

Throws:
ClassCastException

if not JsonNumber

def getFloat(name: String): Float
Implicitly added by toJsonObjectConversion

Gets Float.

Gets Float.

Value parameters:
name

field name

Throws:
ClassCastException

if not JsonNumber

def getInt(index: Int): Int
Implicitly added by toJsonArrayConversion

Gets Int at given index.

Gets Int at given index.

Throws:
ClassCastException

if not JsonNumber

def getInt(name: String): Int
Implicitly added by toJsonObjectConversion

Gets Int.

Gets Int.

Value parameters:
name

field name

Throws:
ClassCastException

if not JsonNumber

def getJsonArray(index: Int): JsonArray
Implicitly added by toJsonArrayConversion

Gets JSON array at given index.

Gets JSON array at given index.

Throws:
ClassCastException

if not JsonArray

def getJsonArray(name: String): JsonArray
Implicitly added by toJsonObjectConversion

Gets JSON array.

Gets JSON array.

Value parameters:
name

field name

Throws:
ClassCastException

if not JsonArray

def getJsonBoolean(index: Int): JsonBoolean
Implicitly added by toJsonArrayConversion

Gets JSON boolean at given index.

Gets JSON boolean at given index.

Throws:
ClassCastException

if not JsonBoolean

def getJsonBoolean(name: String): JsonBoolean
Implicitly added by toJsonObjectConversion

Gets JSON boolean.

Gets JSON boolean.

Value parameters:
name

field name

Throws:
ClassCastException

if not JsonBoolean

def getJsonNull(index: Int): JsonNull
Implicitly added by toJsonArrayConversion

Gets JSON null at given index.

Gets JSON null at given index.

Throws:
ClassCastException

if not JsonNull

def getJsonNull(name: String): JsonNull
Implicitly added by toJsonObjectConversion

Gets JSON null.

Gets JSON null.

Value parameters:
name

field name

Throws:
ClassCastException

if not JsonNull

def getJsonNumber(index: Int): JsonNumber
Implicitly added by toJsonArrayConversion

Gets JSON number at given index.

Gets JSON number at given index.

Throws:
ClassCastException

if not JsonNumber

def getJsonNumber(name: String): JsonNumber
Implicitly added by toJsonObjectConversion

Gets JSON number.

Gets JSON number.

Value parameters:
name

field name

Throws:
ClassCastException

if not JsonNumber

def getJsonObject(index: Int): JsonObject
Implicitly added by toJsonArrayConversion

Gets JSON object at given index.

Gets JSON object at given index.

Throws:
ClassCastException

if not JsonObject

def getJsonObject(name: String): JsonObject
Implicitly added by toJsonObjectConversion

Gets JSON object.

Gets JSON object.

Value parameters:
name

field name

Throws:
ClassCastException

if not JsonObject

def getJsonString(index: Int): JsonString
Implicitly added by toJsonArrayConversion

Gets JSON string at given index.

Gets JSON string at given index.

Throws:
ClassCastException

if not JsonString

def getJsonString(name: String): JsonString
Implicitly added by toJsonObjectConversion

Gets JSON string.

Gets JSON string.

Value parameters:
name

field name

Throws:
ClassCastException

if not JsonString

def getLong(index: Int): Long
Implicitly added by toJsonArrayConversion

Gets Long at given index.

Gets Long at given index.

Throws:
ClassCastException

if not JsonNumber

def getLong(name: String): Long
Implicitly added by toJsonObjectConversion

Gets Long.

Gets Long.

Value parameters:
name

field name

Throws:
ClassCastException

if not JsonNumber

def getOrElse[T](name: String, default: => T)(using JsonInput[T]): T
Implicitly added by toJsonObjectConversion

Gets converted value or returns default if not present.

Gets converted value or returns default if not present.

Value parameters:
default

default value

name

field name

def getShort(index: Int): Short
Implicitly added by toJsonArrayConversion

Gets Short at given index.

Gets Short at given index.

Throws:
ClassCastException

if not JsonNumber

def getShort(name: String): Short
Implicitly added by toJsonObjectConversion

Gets Short.

Gets Short.

Value parameters:
name

field name

Throws:
ClassCastException

if not JsonNumber

def getString(index: Int): String
Implicitly added by toJsonArrayConversion

Gets String at given index.

Gets String at given index.

Throws:
ClassCastException

if not JsonString

def getString(name: String): String
Implicitly added by toJsonObjectConversion

Gets String.

Gets String.

Value parameters:
name

field name

Throws:
ClassCastException

if not JsonString

def isNull(index: Int): Boolean
Implicitly added by toJsonArrayConversion

Tests for null at given index.

Tests for null at given index.

def isNull(name: String): Boolean
Implicitly added by toJsonObjectConversion

Tests for null.

Tests for null.

Value parameters:
name

field name

Throws:
ClassCastException

if not JsonNull

def map[T](name: String)(using JsonInput[T]): Option[T]
Implicitly added by toJsonObjectConversion

Maps optional value excluding null.

Maps optional value excluding null.

Value parameters:
name

field name

Inherited methods

final def as[T](using converter: JsonInput[T]): T
Implicitly added by toJsonArrayConversion

Converts value.

Converts value.

Inherited from:
JsonValue
final def as[T](using converter: JsonInput[T]): T
Implicitly added by toJsonObjectConversion

Converts value.

Converts value.

Inherited from:
JsonValue
def isEmpty: Boolean
Implicitly added by toJsonArrayConversion

Tests for emptiness.

Tests for emptiness.

Inherited from:
JsonStructure
def isEmpty: Boolean
Implicitly added by toJsonObjectConversion

Tests for emptiness.

Tests for emptiness.

Inherited from:
JsonStructure
def size: Int
Implicitly added by toJsonArrayConversion

Gets size.

Gets size.

Inherited from:
JsonStructure
def size: Int
Implicitly added by toJsonObjectConversion

Gets size.

Gets size.

Inherited from:
JsonStructure