A sealed trait representing a JSON value.
The Json type provides a complete representation of JSON data with six possible cases: Object, Array, String, Number, Boolean, and Null.
Key design decisions:
- Objects use
Chunk[(String, Json)]to preserve insertion order - Object equality is order-independent (keys are compared as sets)
- Numbers use
Stringto preserve exact representation - All navigation methods return
JsonSelectionfor fluent chaining
Attributes
- Companion
- object
- Source
- Json.scala
- Graph
-
- Supertypes
- Known subtypes
Members list
Value members
Abstract methods
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] - Source
- Json.scala
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
- Source
- Json.scala
Returns the JsonType of this JSON value.
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
- Source
- Json.scala
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)]] - Source
- Json.scala
Concrete methods
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
- Source
- Json.scala
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
- Source
- Json.scala
Checks if this JSON conforms to a JSON Schema.
Returns true if this JSON conforms to a JSON Schema.
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
- Source
- Json.scala
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
- Source
- Json.scala
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
- Source
- Json.scala
Recursively removes empty objects and arrays.
Recursively removes all null values from objects.
Returns the elements if this is an array, otherwise an empty Chunk.
Returns the fields if this is an object, otherwise an empty Chunk.
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
- Source
- Json.scala
Folds over the JSON structure top-down, allowing failure.
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
- Source
- Json.scala
Folds over the JSON structure bottom-up, allowing failure.
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
- Source
- Json.scala
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
- 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
- Source
- Json.scala
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
- Source
- Json.scala
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
- Source
- Json.scala
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 - Source
- Json.scala
Merges this JSON value with another using the specified strategy.
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
- Source
- Json.scala
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
- Source
- Json.scala
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
- Source
- Json.scala
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) - Source
- Json.scala
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
- Source
- Json.scala
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
- Source
- Json.scala
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
- Source
- Json.scala
Prints this JSON value to a string using the default WriterConfig.
Prints this JSON value to a string using the specified WriterConfig.
Prints this JSON value to a byte array.
Prints this JSON value to a byte array with the specified config.
Prints this JSON value to a Chunk of bytes (UTF-8).
Prints this JSON value to a Chunk of bytes (UTF-8) with configuration.
Prints this JSON value into the provided ByteBuffer.
Prints this JSON value into the provided ByteBuffer with config.
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
- Source
- Json.scala
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 - Source
- Json.scala
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
- Source
- Json.scala
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
- Source
- Json.scala
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 - Source
- Json.scala
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
- Source
- Json.scala
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
- 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 - Source
- Json.scala
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 - Source
- Json.scala
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
- Source
- Json.scala
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
- Source
- Json.scala
Recursively sorts all object keys alphabetically.
Converts this JSON value to a DynamicValue.
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
- Source
- Json.scala
Pretty print Json value to string.
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
- Source
- Json.scala
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
- 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
- Source
- Json.scala