JsonSelection

zio.blocks.schema.json.JsonSelection
See theJsonSelection companion object
final case class JsonSelection(either: Either[SchemaError, Chunk[Json]]) extends AnyVal

A wrapper around Either[SchemaError, Chunk[Json]] that provides fluent chaining for JSON navigation and querying operations.

JsonSelection enables a fluent API style for navigating through JSON structures:

import zio.blocks.schema.json._

val json = Json.Object(
 "users" -> Json.Array(
   Json.Object("name" -> Json.String("Alice"))
 )
)

val names: JsonSelection =
 json.get("users").arrays.apply(0).get("name").strings

The selection can contain zero, one, or multiple JSON values, supporting both single-value navigation and multi-value queries.

Attributes

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

Members list

Value members

Concrete methods

Combines two selections, concatenating their values.

Combines two selections, concatenating their values.

Attributes

Source
JsonSelection.scala
def all: Either[SchemaError, Json]

Returns all selected values condensed into a single Json. If there are multiple values, wraps them in an array. Fails if the selection is empty or an error.

Returns all selected values condensed into a single Json. If there are multiple values, wraps them in an array. Fails if the selection is empty or an error.

Attributes

Source
JsonSelection.scala
def any: Either[SchemaError, Json]

Returns any single value from the selection. Fails if the selection is empty or an error.

Returns any single value from the selection. Fails if the selection is empty or an error.

Attributes

Source
JsonSelection.scala

Unsafe version of any - throws SchemaError on error.

Unsafe version of any - throws SchemaError on error.

Attributes

Source
JsonSelection.scala
def apply(index: Int): JsonSelection

Navigates to an index in each array.

Navigates to an index in each array.

Attributes

Source
JsonSelection.scala
def apply(key: String): JsonSelection

Navigates to a field in each object (alias for get).

Navigates to a field in each object (alias for get).

Attributes

Source
JsonSelection.scala

Navigates using a DynamicOptic path (alias for get).

Navigates using a DynamicOptic path (alias for get).

Attributes

Source
JsonSelection.scala

Keeps only array values.

Keeps only array values.

Attributes

Source
JsonSelection.scala
def as[A](implicit schema: Schema[A]): Either[SchemaError, A]

Decodes the single selected value to type A.

Decodes the single selected value to type A.

Attributes

Source
JsonSelection.scala
def as(jsonType: JsonType): Either[SchemaError, jsonType.Type]

Narrows the single selected value to the specified JSON type. Fails if there are 0 or more than 1 values, or if the value doesn't match.

Narrows the single selected value to the specified JSON type. Fails if there are 0 or more than 1 values, or if the value doesn't match.

Attributes

Source
JsonSelection.scala
def asAll[A](implicit schema: Schema[A]): Either[SchemaError, Chunk[A]]

Decodes all selected values to type A.

Decodes all selected values to type A.

Attributes

Source
JsonSelection.scala
def asAll(jsonType: JsonType): Either[SchemaError, Chunk[jsonType.Type]]

Narrows all selected values to the specified JSON type. Values not matching the type are silently dropped.

Narrows all selected values to the specified JSON type. Values not matching the type are silently dropped.

Attributes

Source
JsonSelection.scala

Keeps only boolean values.

Keeps only boolean values.

Attributes

Source
JsonSelection.scala
def collect[A](pf: PartialFunction[Json, A]): Either[SchemaError, Chunk[A]]

Collects values for which the partial function is defined.

Collects values for which the partial function is defined.

Attributes

Source
JsonSelection.scala

Deletes the value at the given path in each selected value.

Deletes the value at the given path in each selected value.

Attributes

Source
JsonSelection.scala

Deletes the value at the given path. Fails if the path doesn't exist.

Deletes the value at the given path. Fails if the path doesn't exist.

Attributes

Source
JsonSelection.scala

Recursively removes empty objects and arrays in each selected value.

Recursively removes empty objects and arrays in each selected value.

Attributes

Source
JsonSelection.scala

Recursively removes all null values from objects in each selected value.

Recursively removes all null values from objects in each selected value.

Attributes

Source
JsonSelection.scala
def error: Option[SchemaError]

Returns the error if this is a failure, otherwise None.

Returns the error if this is a failure, otherwise None.

Attributes

Source
JsonSelection.scala
def filter(p: Json => Boolean): JsonSelection

Filters selected values based on a predicate.

Filters selected values based on a predicate.

Attributes

Source
JsonSelection.scala

FlatMaps a function over all selected values, combining results.

FlatMaps a function over all selected values, combining results.

Attributes

Source
JsonSelection.scala
def get(key: String): JsonSelection

Navigates to a field in each object.

Navigates to a field in each object.

Attributes

Source
JsonSelection.scala

Navigates using a DynamicOptic path.

Navigates using a DynamicOptic path.

Attributes

Source
JsonSelection.scala
def getOrElse(default: => Chunk[Json]): Chunk[Json]

Returns this selection's values, or the default on failure.

Returns this selection's values, or the default on failure.

Attributes

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

Inserts a value at the given path in each selected value.

Inserts a value at the given path in each selected value.

Attributes

Source
JsonSelection.scala

Inserts a value at the given path. Fails if the path already exists or the parent doesn't exist.

Inserts a value at the given path. Fails if the path already exists or the parent doesn't exist.

Attributes

Source
JsonSelection.scala
def isEmpty: Boolean

Returns true if this selection is empty (no values or error).

Returns true if this selection is empty (no values or error).

Attributes

Source
JsonSelection.scala
def isFailure: Boolean

Returns true if the selection is a failure.

Returns true if the selection is a failure.

Attributes

Source
JsonSelection.scala
def isSuccess: Boolean

Returns true if the selection is successful (contains values).

Returns true if the selection is successful (contains values).

Attributes

Source
JsonSelection.scala
def map(f: Json => Json): JsonSelection

Maps a function over all selected values.

Maps a function over all selected values.

Attributes

Source
JsonSelection.scala
def merge(that: JsonSelection, strategy: MergeStrategy = ...): JsonSelection

Merges each value in this selection with each value in that selection. Uses cartesian product semantics: if this has N values and that has M values, the result has N × M values.

Merges each value in this selection with each value in that selection. Uses cartesian product semantics: if this has N values and that has M values, the result has N × M values.

Attributes

Source
JsonSelection.scala

Modifies the value at the given path in each selected value.

Modifies the value at the given path in each selected value.

Attributes

Source
JsonSelection.scala
def modifyOrFail(path: DynamicOptic)(pf: PartialFunction[Json, Json]): JsonSelection

Modifies values at the given path using a partial function. Fails if the path doesn't exist or the partial function is not defined.

Modifies values at the given path using a partial function. Fails if the path doesn't exist or the partial function is not defined.

Attributes

Source
JsonSelection.scala
def nonEmpty: Boolean

Returns true if this selection contains at least one value.

Returns true if this selection contains at least one value.

Attributes

Source
JsonSelection.scala

Applies sortKeys, dropNulls, and dropEmpty to each selected value.

Applies sortKeys, dropNulls, and dropEmpty to each selected value.

Attributes

Source
JsonSelection.scala

Keeps only null values.

Keeps only null values.

Attributes

Source
JsonSelection.scala

Keeps only number values.

Keeps only number values.

Attributes

Source
JsonSelection.scala

Keeps only object values.

Keeps only object values.

Attributes

Source
JsonSelection.scala
def one: Either[SchemaError, Json]

Returns the single selected value, or fails if there are 0 or more than 1 values.

Returns the single selected value, or fails if there are 0 or more than 1 values.

Attributes

Source
JsonSelection.scala

Unsafe version of one - throws SchemaError on error.

Unsafe version of one - throws SchemaError on error.

Attributes

Source
JsonSelection.scala
def orElse(alternative: => JsonSelection): JsonSelection

Returns this selection if successful, otherwise the alternative.

Returns this selection if successful, otherwise the alternative.

Attributes

Source
JsonSelection.scala

Projects each selected value to only include the specified paths.

Projects each selected value to only include the specified paths.

Attributes

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

Removes values matching the predicate from each selected value.

Removes values matching the predicate from each selected value.

Attributes

Source
JsonSelection.scala
def pruneBoth(p: (DynamicOptic, Json) => Boolean): JsonSelection

Removes values matching both path and value predicates from each selected value.

Removes values matching both path and value predicates from each selected value.

Attributes

Source
JsonSelection.scala
def prunePath(p: DynamicOptic => Boolean): JsonSelection

Removes values at paths matching the predicate from each selected value.

Removes values at paths matching the predicate from each selected value.

Attributes

Source
JsonSelection.scala
def query(p: Json => Boolean): JsonSelection

Recursively searches each JSON in the selection, collecting all values for which the predicate returns true.

Recursively searches each JSON in the selection, collecting all values for which the predicate returns true.

Attributes

Example
selection.query(JsonType.String) // all string values in selection
Source
JsonSelection.scala
def queryBoth(p: (DynamicOptic, Json) => Boolean): JsonSelection

Recursively searches each JSON in the selection, collecting all values for which the predicate on both path and value returns true.

Recursively searches each JSON in the selection, collecting all values for which the predicate on both path and value returns true.

Attributes

Source
JsonSelection.scala
def queryPath(p: DynamicOptic => Boolean): JsonSelection

Recursively searches each JSON in the selection, collecting all values at paths for which the predicate returns true.

Recursively searches each JSON in the selection, collecting all values at paths for which the predicate returns true.

Attributes

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

Retains only values matching the predicate in each selected value.

Retains only values matching the predicate in each selected value.

Attributes

Source
JsonSelection.scala
def retainBoth(p: (DynamicOptic, Json) => Boolean): JsonSelection

Retains only values matching both path and value predicates in each selected value.

Retains only values matching both path and value predicates in each selected value.

Attributes

Source
JsonSelection.scala
def retainPath(p: DynamicOptic => Boolean): JsonSelection

Retains only values at paths matching the predicate in each selected value.

Retains only values at paths matching the predicate in each selected value.

Attributes

Source
JsonSelection.scala
def set(path: DynamicOptic, value: Json): JsonSelection

Sets a value at the given path in each selected value.

Sets a value at the given path in each selected value.

Attributes

Source
JsonSelection.scala

Sets a value at the given path. Fails if the path doesn't exist.

Sets a value at the given path. Fails if the path doesn't exist.

Attributes

Source
JsonSelection.scala
def size: Int

Returns the number of selected values (0 on error).

Returns the number of selected values (0 on error).

Attributes

Source
JsonSelection.scala

Recursively sorts all object keys alphabetically in each selected value.

Recursively sorts all object keys alphabetically in each selected value.

Attributes

Source
JsonSelection.scala

Keeps only string values.

Keeps only string values.

Attributes

Source
JsonSelection.scala
def toArray: Either[SchemaError, Json]

Returns all selected values as a JSON array.

Returns all selected values as a JSON array.

Attributes

Source
JsonSelection.scala

Returns the selected values as a Chunk, or an empty Chunk on failure.

Returns the selected values as a Chunk, or an empty Chunk on failure.

Attributes

Source
JsonSelection.scala

Transforms each selected value top-down using the given function.

Transforms each selected value top-down using the given function.

Attributes

Source
JsonSelection.scala
def transformKeys(f: (DynamicOptic, String) => String): JsonSelection

Transforms all object keys in each selected value using the given function.

Transforms all object keys in each selected value using the given function.

Attributes

Source
JsonSelection.scala

Transforms each selected value bottom-up using the given function.

Transforms each selected value bottom-up using the given function.

Attributes

Source
JsonSelection.scala
def unwrap(jsonType: JsonType): Either[SchemaError, jsonType.Unwrap]

Extracts the underlying Scala value from the single selected JSON value. Fails if there are 0 or more than 1 values, or if the value doesn't match.

Extracts the underlying Scala value from the single selected JSON value. Fails if there are 0 or more than 1 values, or if the value doesn't match.

Note: For JsonType.Number, this parses to BigDecimal and may fail if not parseable.

Attributes

Source
JsonSelection.scala
def unwrapAll(jsonType: JsonType): Either[SchemaError, Chunk[jsonType.Unwrap]]

Extracts the underlying Scala values from all selected JSON values. Values not matching the type (or unparseable for Number) are silently dropped.

Extracts the underlying Scala values from all selected JSON values. Values not matching the type (or unparseable for Number) are silently dropped.

Attributes

Source
JsonSelection.scala
def values: Option[Chunk[Json]]

Returns the selected values if successful, otherwise None.

Returns the selected values if successful, otherwise None.

Attributes

Source
JsonSelection.scala

Inherited methods

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