Array

zio.blocks.schema.json.Json.Array
See theArray companion object
final case class Array(value: Chunk[Json]) extends Json

Represents a JSON array.

Attributes

Companion
object
Source
Json.scala
Graph
Supertypes
trait Serializable
trait Product
trait Equals
trait Json
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

override def as(jsonType: JsonType): Option[jsonType.Type]

Narrows this JSON value to the specified type, returning Some if the types match or None otherwise. The return type is path-dependent on the jsonType parameter.

Narrows this JSON value to the specified type, returning Some if the types match or None otherwise. The return type is path-dependent on the jsonType parameter.

Attributes

Example
 json.as(JsonType.Object) // Option[Json.Object]
 json.as(JsonType.String) // Option[Json.String] 
Definition Classes
Source
Json.scala
override def compare(that: Json): Int

Compares this JSON value with another for ordering. Objects are compared as sorted key-value pairs (order-independent).

Compares this JSON value with another for ordering. Objects are compared as sorted key-value pairs (order-independent).

Attributes

Definition Classes
Source
Json.scala
override def dropEmpty: Json

Recursively removes empty objects and arrays.

Recursively removes empty objects and arrays.

Attributes

Definition Classes
Source
Json.scala
override def dropNulls: Json

Recursively removes all null values from objects.

Recursively removes all null values from objects.

Attributes

Definition Classes
Source
Json.scala
override def elements: Chunk[Json]

Returns the elements if this is an array, otherwise an empty Chunk.

Returns the elements if this is an array, otherwise an empty Chunk.

Attributes

Definition Classes
Source
Json.scala
override def get(index: Int): JsonSelection

Navigates to an element in an array by index. Returns a JsonSelection containing the value, or an error if index is out of bounds.

Navigates to an element in an array by index. Returns a JsonSelection containing the value, or an error if index is out of bounds.

Attributes

Definition Classes
Source
Json.scala
override def jsonType: JsonType

Returns the JsonType of this JSON value.

Returns the JsonType of this JSON value.

Attributes

Definition Classes
Source
Json.scala
override def normalize: Json

Applies dropNulls, dropEmpty, and sortKeys, but more efficiently than just their calls in a sequence.

Applies dropNulls, dropEmpty, and sortKeys, but more efficiently than just their calls in a sequence.

Attributes

Definition Classes
Source
Json.scala
override def sortKeys: Json

Recursively sorts all object keys alphabetically.

Recursively sorts all object keys alphabetically.

Attributes

Definition Classes
Source
Json.scala
override def typeIndex: Int

Returns the type index for ordering: Null=0, Boolean=1, Number=2, String=3, Array=4, Object=5

Returns the type index for ordering: Null=0, Boolean=1, Number=2, String=3, Array=4, Object=5

Attributes

Definition Classes
Source
Json.scala
override def unwrap(jsonType: JsonType): Option[jsonType.Unwrap]

Extracts the underlying value from this JSON if it matches the specified type. The return type is path-dependent on the jsonType parameter.

Extracts the underlying value from this JSON if it matches the specified type. The return type is path-dependent on the jsonType parameter.

Attributes

Example
 json.unwrap(JsonType.String) // Option[String]
 json.unwrap(JsonType.Number) // Option[BigDecimal]
 json.unwrap(JsonType.Object) // Option[Chunk[(String, Json)]] 
Definition Classes
Source
Json.scala

Inherited methods

def as[A](implicit schema: Schema[A]): Either[SchemaError, A]

Decodes this JSON value to a value of type A using the implicit JsonDecoder.

Decodes this JSON value to a value of type A using the implicit JsonDecoder.

Attributes

Inherited from:
Json
Source
Json.scala
def asUnsafe[A](implicit schema: Schema[A]): A

Decodes this JSON value to a value of type A, throwing SchemaError on failure.

Decodes this JSON value to a value of type A, throwing SchemaError on failure.

Attributes

Inherited from:
Json
Source
Json.scala
def check(schema: JsonSchema): Option[SchemaError]

Checks if this JSON conforms to a JSON Schema.

Checks if this JSON conforms to a JSON Schema.

Attributes

Inherited from:
Json
Source
Json.scala
def conforms(schema: JsonSchema): Boolean

Returns true if this JSON conforms to a JSON Schema.

Returns true if this JSON conforms to a JSON Schema.

Attributes

Inherited from:
Json
Source
Json.scala
def delete(path: DynamicOptic): Json

Deletes the value at the given path. If the path doesn't exist, returns the original JSON unchanged.

Deletes the value at the given path. If the path doesn't exist, returns the original JSON unchanged.

Attributes

Inherited from:
Json
Source
Json.scala
def deleteOrFail(path: DynamicOptic): Either[SchemaError, Json]

Deletes the value at the given path. Returns Left with an error if the path doesn't exist.

Deletes the value at the given path. Returns Left with an error if the path doesn't exist.

Attributes

Inherited from:
Json
Source
Json.scala
def diff(that: Json): JsonPatch

Computes the difference between this JSON and another.

Computes the difference between this JSON and another.

Value parameters

that

The target JSON value

Attributes

Returns

A JsonPatch that transforms this to that

Inherited from:
Json
Source
Json.scala
def fields: Chunk[(String, Json)]

Returns the fields if this is an object, otherwise an empty Chunk.

Returns the fields if this is an object, otherwise an empty Chunk.

Attributes

Inherited from:
Json
Source
Json.scala
def foldDown[B](z: B)(f: (DynamicOptic, Json, B) => B): B

Folds over the JSON structure top-down. The function receives the current path, the JSON value, and the accumulator. Parent values are folded before their children.

Folds over the JSON structure top-down. The function receives the current path, the JSON value, and the accumulator. Parent values are folded before their children.

Attributes

Inherited from:
Json
Source
Json.scala
def foldDownOrFail[B](z: B)(f: (DynamicOptic, Json, B) => Either[SchemaError, B]): Either[SchemaError, B]

Folds over the JSON structure top-down, allowing failure.

Folds over the JSON structure top-down, allowing failure.

Attributes

Inherited from:
Json
Source
Json.scala
def foldUp[B](z: B)(f: (DynamicOptic, Json, B) => B): B

Folds over the JSON structure bottom-up. The function receives the current path, the JSON value, and the accumulator. Child values are folded before their parents.

Folds over the JSON structure bottom-up. The function receives the current path, the JSON value, and the accumulator. Child values are folded before their parents.

Attributes

Inherited from:
Json
Source
Json.scala
def foldUpOrFail[B](z: B)(f: (DynamicOptic, Json, B) => Either[SchemaError, B]): Either[SchemaError, B]

Folds over the JSON structure bottom-up, allowing failure.

Folds over the JSON structure bottom-up, allowing failure.

Attributes

Inherited from:
Json
Source
Json.scala

Navigates to the value(s) at the given path. Returns a JsonSelection that may contain zero or more values.

Navigates to the value(s) at the given path. Returns a JsonSelection that may contain zero or more values.

Attributes

Inherited from:
Json
Source
Json.scala
def get(key: String): JsonSelection

Navigates to a field in an object by key. Returns a JsonSelection containing the value, or an error if not found.

Navigates to a field in an object by key. Returns a JsonSelection containing the value, or an error if not found.

Attributes

Inherited from:
Json
Source
Json.scala
def insert(path: DynamicOptic, value: Json): Json

Inserts a value at the given path. For arrays, inserts at the specified index. For objects, adds the field. If the path already exists, returns the original JSON unchanged.

Inserts a value at the given path. For arrays, inserts at the specified index. For objects, adds the field. If the path already exists, returns the original JSON unchanged.

Attributes

Inherited from:
Json
Source
Json.scala
def insertOrFail(path: DynamicOptic, value: Json): Either[SchemaError, Json]

Inserts a value at the given path. Returns Left with an error if the path already exists or the parent doesn't exist.

Inserts a value at the given path. Returns Left with an error if the path already exists or the parent doesn't exist.

Attributes

Inherited from:
Json
Source
Json.scala
def is(jsonType: JsonType): Boolean

Returns true if this JSON value is of the specified type.

Returns true if this JSON value is of the specified type.

Attributes

Example
 json.is(JsonType.Object) // true if json is an object
 json.is(JsonType.String) // true if json is a string 
Inherited from:
Json
Source
Json.scala
def merge(that: Json, strategy: MergeStrategy = ...): Json

Merges this JSON value with another using the specified strategy.

Merges this JSON value with another using the specified strategy.

Attributes

Inherited from:
Json
Source
Json.scala
def modify(path: DynamicOptic)(f: Json => Json): Json

Modifies the value at the given path using a function. If the path doesn't exist, returns the original JSON unchanged.

Modifies the value at the given path using a function. If the path doesn't exist, returns the original JSON unchanged.

Attributes

Inherited from:
Json
Source
Json.scala
def modifyOrFail(path: DynamicOptic)(pf: PartialFunction[Json, Json]): Either[SchemaError, Json]

Modifies the value at the given path using a partial function. Returns Left with an error if the path doesn't exist or the partial function is not defined.

Modifies the value at the given path using a partial function. Returns Left with an error if the path doesn't exist or the partial function is not defined.

Attributes

Inherited from:
Json
Source
Json.scala
def partition(p: Json => Boolean): (Json, Json)

Partitions elements/fields based on a predicate on the value. Returns a tuple of (matching, non-matching) JSON values.

Partitions elements/fields based on a predicate on the value. Returns a tuple of (matching, non-matching) JSON values.

Attributes

Example
json.partition(_.is(JsonType.Number)) // (numbers, non-numbers)
Inherited from:
Json
Source
Json.scala
def partitionBoth(p: (DynamicOptic, Json) => Boolean): (Json, Json)

Partitions elements/fields based on a predicate on both path and value. Returns a tuple of (matching, non-matching) JSON values.

Partitions elements/fields based on a predicate on both path and value. Returns a tuple of (matching, non-matching) JSON values.

Attributes

Inherited from:
Json
Source
Json.scala
def partitionPath(p: DynamicOptic => Boolean): (Json, Json)

Partitions elements/fields based on a predicate on the path. Returns a tuple of (matching, non-matching) JSON values.

Partitions elements/fields based on a predicate on the path. Returns a tuple of (matching, non-matching) JSON values.

Attributes

Inherited from:
Json
Source
Json.scala
def patch(patch: JsonPatch, mode: PatchMode = ...): Either[SchemaError, Json]

Applies a JSON patch to this value.

Applies a JSON patch to this value.

Value parameters

mode

The patch mode controlling failure handling (default: Strict)

patch

The patch to apply

Attributes

Returns

Either an error or the patched value

Inherited from:
Json
Source
Json.scala
def printBytes(config: WriterConfig): Array[Byte]

Prints this JSON value to a byte array with the specified config.

Prints this JSON value to a byte array with the specified config.

Attributes

Inherited from:
Json
Source
Json.scala
def printBytes: Array[Byte]

Prints this JSON value to a byte array.

Prints this JSON value to a byte array.

Attributes

Inherited from:
Json
Source
Json.scala
def printChunk(config: WriterConfig): Chunk[Byte]

Prints this JSON value to a Chunk of bytes (UTF-8) with configuration.

Prints this JSON value to a Chunk of bytes (UTF-8) with configuration.

Attributes

Inherited from:
Json
Source
Json.scala
def printChunk: Chunk[Byte]

Prints this JSON value to a Chunk of bytes (UTF-8).

Prints this JSON value to a Chunk of bytes (UTF-8).

Attributes

Inherited from:
Json
Source
Json.scala
def printTo(buffer: ByteBuffer, config: WriterConfig): Unit

Prints this JSON value into the provided ByteBuffer with config.

Prints this JSON value into the provided ByteBuffer with config.

Attributes

Inherited from:
Json
Source
Json.scala
def printTo(buffer: ByteBuffer): Unit

Prints this JSON value into the provided ByteBuffer.

Prints this JSON value into the provided ByteBuffer.

Attributes

Inherited from:
Json
Source
Json.scala
def productElementNames: Iterator[String]

An iterator over the names of all the elements of this product.

An iterator over the names of all the elements of this product.

Attributes

Inherited from:
Product
Source
Product.scala
def productIterator: Iterator[Any]

An iterator over all the elements of this product.

An iterator over all the elements of this product.

Attributes

Returns

in the default implementation, an Iterator[Any]

Inherited from:
Product
Source
Product.scala
def project(paths: DynamicOptic*): Json

Projects only the specified paths from this JSON value. Creates a new JSON containing only values at the given paths.

Projects only the specified paths from this JSON value. Creates a new JSON containing only values at the given paths.

Attributes

Inherited from:
Json
Source
Json.scala
def prune(p: Json => Boolean): Json

Recursively removes elements/fields for which the predicate returns true.

Recursively removes elements/fields for which the predicate returns true.

Attributes

Example
json.prune(_.is(JsonType.Null)) // removes all null values
Inherited from:
Json
Source
Json.scala
def pruneBoth(p: (DynamicOptic, Json) => Boolean): Json

Recursively removes elements/fields for which the predicate on both path and value returns true.

Recursively removes elements/fields for which the predicate on both path and value returns true.

Attributes

Inherited from:
Json
Source
Json.scala
def prunePath(p: DynamicOptic => Boolean): Json

Recursively removes elements/fields at paths for which the predicate returns true.

Recursively removes elements/fields at paths for which the predicate returns true.

Attributes

Inherited from:
Json
Source
Json.scala
def retain(p: Json => Boolean): Json

Recursively keeps only elements/fields for which the predicate returns true.

Recursively keeps only elements/fields for which the predicate returns true.

Attributes

Example
json.retain(_.is(JsonType.Number)) // keeps only numbers
Inherited from:
Json
Source
Json.scala
def retainBoth(p: (DynamicOptic, Json) => Boolean): Json

Recursively keeps only elements/fields for which the predicate on both path and value returns true.

Recursively keeps only elements/fields for which the predicate on both path and value returns true.

Attributes

Inherited from:
Json
Source
Json.scala
def retainPath(p: DynamicOptic => Boolean): Json

Recursively keeps only elements/fields at paths for which the predicate returns true.

Recursively keeps only elements/fields at paths for which the predicate returns true.

Attributes

Inherited from:
Json
Source
Json.scala
def select(jsonType: JsonType): JsonSelection

Wraps this JSON value in a JsonSelection if its type matches the specified JsonType, otherwise returns an empty selection.

Wraps this JSON value in a JsonSelection if its type matches the specified JsonType, otherwise returns an empty selection.

This is a flat (non-recursive) type check on the current node only.

Attributes

Example
json.select(JsonType.Object) // selection if json is object, else empty
Inherited from:
Json
Source
Json.scala

Wraps this JSON value in a JsonSelection.

Wraps this JSON value in a JsonSelection.

Attributes

Example
json.select // JsonSelection containing this value
Inherited from:
Json
Source
Json.scala
def set(path: DynamicOptic, value: Json): Json

Sets a value at the given path. If the path doesn't exist, returns the original JSON unchanged.

Sets a value at the given path. If the path doesn't exist, returns the original JSON unchanged.

Attributes

Inherited from:
Json
Source
Json.scala
def setOrFail(path: DynamicOptic, value: Json): Either[SchemaError, Json]

Sets a value at the given path. Returns Left with an error if the path doesn't exist.

Sets a value at the given path. Returns Left with an error if the path doesn't exist.

Attributes

Inherited from:
Json
Source
Json.scala

Converts this JSON value to a DynamicValue.

Converts this JSON value to a DynamicValue.

Attributes

Inherited from:
Json
Source
Json.scala

Converts this JSON to a Chunk of path-value pairs. Each pair contains the path to a leaf value and the value itself.

Converts this JSON to a Chunk of path-value pairs. Each pair contains the path to a leaf value and the value itself.

Attributes

Inherited from:
Json
Source
Json.scala
override def toString: String

Pretty print Json value to string.

Pretty print Json value to string.

Attributes

Definition Classes
Json -> Any
Inherited from:
Json
Source
Json.scala

Transforms this JSON value top-down using the given function. The function receives the current path and the JSON value at that path. Parent values are transformed before their children.

Transforms this JSON value top-down using the given function. The function receives the current path and the JSON value at that path. Parent values are transformed before their children.

Attributes

Inherited from:
Json
Source
Json.scala
def transformKeys(f: (DynamicOptic, String) => String): Json

Transforms all object keys using the given function. The function receives the current path and the key at that path.

Transforms all object keys using the given function. The function receives the current path and the key at that path.

Attributes

Inherited from:
Json
Source
Json.scala

Transforms this JSON value bottom-up using the given function. The function receives the current path and the JSON value at that path. Child values are transformed before their parents.

Transforms this JSON value bottom-up using the given function. The function receives the current path and the JSON value at that path. Child values are transformed before their parents.

Attributes

Inherited from:
Json
Source
Json.scala