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
Members list
Value members
Concrete methods
Combines two selections, concatenating their values.
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
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.
Navigates to an index in each array.
Navigates to a field in each object (alias for get).
Navigates using a DynamicOptic path (alias for get).
Keeps only array values.
Decodes the single selected value to type A.
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
Decodes all selected values to type A.
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.
Collects values for which the partial function is defined.
Deletes the value at the given path in each selected value.
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
Returns the error if this is a failure, otherwise None.
Filters selected values based on a predicate.
FlatMaps a function over all selected values, combining results.
FlatMaps a function over all selected values, combining results.
Attributes
- Source
- JsonSelection.scala
Navigates to a field in each object.
Navigates using a DynamicOptic path.
Returns this selection's values, or the default on failure.
Inserts a value at the given path in each selected value.
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
Returns true if this selection is empty (no values or error).
Returns true if the selection is a failure.
Returns true if the selection is successful (contains values).
Returns true if the selection is successful (contains values).
Attributes
- Source
- JsonSelection.scala
Maps a function over all selected 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.
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 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
Returns true if this selection contains at least one value.
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 number values.
Keeps only object values.
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.
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
Removes values matching the predicate from each selected value.
Removes values matching the predicate from each selected value.
Attributes
- Source
- JsonSelection.scala
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
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
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
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
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
Retains only values matching the predicate in each selected value.
Retains only values matching the predicate in each selected value.
Attributes
- Source
- JsonSelection.scala
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
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
Sets a value at the given path in each selected value.
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
Returns the number of selected values (0 on error).
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.
Returns all selected values as a JSON array.
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
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
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
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
Returns the selected values if successful, otherwise None.
Inherited methods
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
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