zio.blocks.schema.json
Members list
Type members
Classlikes
Attributes
- Companion
- class
- Source
- JsonSchema.scala
- Supertypes
- Self type
-
Anchor.type
Anchor name (plain name fragment without #).
Anchor name (plain name fragment without #).
Attributes
- Companion
- object
- Source
- JsonSchema.scala
- Supertypes
Attributes
- Companion
- trait
- Source
- DiscriminatorKind.scala
- Supertypes
- Self type
-
DiscriminatorKind.type
Represents the strategy for specifying the discriminator used in a JSON schema for distinguishing between different subtypes of a sealed hierarchy.
Represents the strategy for specifying the discriminator used in a JSON schema for distinguishing between different subtypes of a sealed hierarchy.
Implementations of this trait define how the discriminator is represented in the serialized JSON, if any.
The possible discriminator kinds include:
Fieldwith adding a custom field named as specified in thenameparameter that contains a value of the subtype discriminator, e.g.{"type": "Person", ...}forcase class Person(...) extends SealedTraitKey, where the discriminator is represented as a JSON object key with wrapping of the encoded value in a JSON object, e.g.{"Person":{...}}forcase class Person(...) extends SealedTrait.None, where no discriminator is used, meaning subtype differentiation is handled by sequential attempts to parse all possible subtypes, starting from the first subtype, until a successful parse is found, or an error is thrown if none of the subtypes can be parsed from the input.
Attributes
- Companion
- object
- Source
- DiscriminatorKind.scala
- Supertypes
- Known subtypes
Result of schema validation that tracks evaluated properties and items.
Result of schema validation that tracks evaluated properties and items.
Per JSON Schema 2020-12, unevaluatedProperties and unevaluatedItems need to know which properties/items were evaluated by any applicator keyword in the schema tree.
Value parameters
- errors
-
Accumulated validation errors
- evaluatedItems
-
Set of array indices that were evaluated by applicator keywords
- evaluatedProperties
-
Set of property names that were evaluated by applicator keywords
Attributes
- Companion
- object
- Source
- JsonSchema.scala
- Supertypes
Attributes
- Companion
- class
- Source
- JsonSchema.scala
- Supertypes
- Self type
-
EvaluationResult.type
Attributes
- Companion
- trait
- Source
- Json.scala
- Supertypes
- Self type
-
Json.type
A sealed trait representing a JSON value.
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
- Supertypes
- Known subtypes
Abstract class for encoding and decoding values of type A to and from JSON formats. Encapsulates logic to map JSON representations into native type structures and vice versa, handling serialization and deserialization as per JSON encoding standards using UTF-8 character set.
Abstract class for encoding and decoding values of type A to and from JSON formats. Encapsulates logic to map JSON representations into native type structures and vice versa, handling serialization and deserialization as per JSON encoding standards using UTF-8 character set.
This class requires an implementation for two core operations: decoding a value of type A from a JSON representation and encoding a value of type A into a JSON representation.
Attributes
- Companion
- object
- Source
- JsonCodec.scala
- Supertypes
A utility object that provides constants and thread-local pools for encoding and decoding JSON structures. The object defines various type constants that represent different data types and maintains ThreadLocal pools for JsonReader and JsonWriter instances to ensure their efficient reuse.
A utility object that provides constants and thread-local pools for encoding and decoding JSON structures. The object defines various type constants that represent different data types and maintains ThreadLocal pools for JsonReader and JsonWriter instances to ensure their efficient reuse.
The JsonCodec is designed for use with methods from its associated companion type, providing a lower-level abstraction to interact with JSON-encoded binary data. These utility pools help manage reading and writing operations in a thread-safe manner while also improving performance.
Attributes
- Companion
- class
- Source
- JsonCodec.scala
- Supertypes
- Self type
-
JsonCodec.type
Provides a default implementation of JsonCodecDeriver with customizable settings for JSON and binary codec derivation. This object allows the derivation of codecs for various data types, including primitives, records, variants, sequences, maps, and dynamic values.
Provides a default implementation of JsonCodecDeriver with customizable settings for JSON and binary codec derivation. This object allows the derivation of codecs for various data types, including primitives, records, variants, sequences, maps, and dynamic values.
The derivation process can be customized through pre-configured parameters, including:
fieldNameMapper: Controls how field names are transformed during serialization and deserialization.caseNameMapper: Controls how case names in variants are transformed.discriminatorKind: Determines the strategy for handling type discriminators in variants.rejectExtraFields: Specifies if unrecognized fields should cause validation errors.enumValuesAsStrings: Specifies whether enumeration values are represented as strings.transientNone: Excludes fields with a value ofNone(forOption) or absent (forMaybe) during serialization.requireOptionFields: Enforces the inclusion of optional fields (OptionandMaybe) in deserialization.transientEmptyCollection: Excludes empty collections during serialization.requireCollectionFields: Enforces the inclusion of collection fields in deserialization.transientDefaultValue: Excludes fields with default values during serialization.requireDefaultValueFields: Enforces the inclusion of fields with default values in deserialization.
This predefined object uses the NameMapper.Identity strategy, which applies no transformation to field or case names, and DiscriminatorKind.Key, which embeds type information as a key in serialized data.
Attributes
- Companion
- class
- Source
- JsonCodecDeriver.scala
- Supertypes
- Self type
-
JsonCodecDeriver.type
Attributes
- Companion
- object
- Source
- JsonCodecDeriver.scala
- Supertypes
- Known subtypes
-
object JsonCodecDeriver
A custom exception class without the stack trace representing errors that occur during JSON encoding/decoding operations.
A custom exception class without the stack trace representing errors that occur during JSON encoding/decoding operations.
The JsonCodecError class extends Throwable to provide enhanced error reporting for scenarios involving JSON encoding or decoding errors where dynamic data paths (spans) are involved. These spans represent the stack of nodes traversed within the data structure when the error occurred. So that top-level spans are at the end of the list.
Value parameters
- message
-
A descriptive message providing additional context or details about the error.
- spans
-
A list of
DynamicOptic.Nodeobjects representing the traversal path within the data structure where the error occurred. Each node encapsulates information about a specific element (field, index, etc.).
Attributes
- Source
- JsonCodecError.scala
- Supertypes
Computes differences between Json values, producing JsonPatch instances that can transform one JSON value into another.
Computes differences between Json values, producing JsonPatch instances that can transform one JSON value into another.
Attributes
- Source
- JsonDiffer.scala
- Supertypes
- Self type
-
JsonDiffer.type
An object that represents the JSON format used for serialization and deserialization.
An object that represents the JSON format used for serialization and deserialization.
It extends the BinaryFormat class, specifying "application/json" as the MIME type and utilizing the JsonCodecDeriver for deriving the necessary codecs.
Attributes
- Source
- JsonCodecDeriver.scala
- Supertypes
- Self type
-
JsonFormat.type
Provides matching logic for SchemaRepr patterns against Json instances.
Provides matching logic for SchemaRepr patterns against Json instances.
This object implements structural pattern matching between schema representations and JSON values, enabling the search optic to find JSON values that match a given schema pattern.
==Matching Rules==
- '''Wildcard''': Matches any Json value
- '''Primitive(name)''': Matches Json primitive types:
- "string" matches Json.String
- "boolean" matches Json.Boolean
- "int", "long", "short", "byte", "float", "double", "number", "bigint", "bigdecimal" all match Json.Number
- "null" matches Json.Null
- '''Record(fields)''': Matches Json.Object using subset matching - all specified fields must exist with matching types, but extra fields are allowed
- '''Variant(cases)''': Returns false (JSON doesn't have tagged variants)
- '''Sequence(elem)''': Matches Json.Array if all elements match the element pattern (empty array always matches)
- '''Map(k, v)''': Matches Json.Object if key pattern is "string" and all values match the value pattern (empty object always matches)
- '''Optional(inner)''': Matches Json.Null always, otherwise checks inner pattern
- '''Nominal(name)''': Returns false (requires schema context not available in JSON)
Attributes
- Source
- JsonMatch.scala
- Supertypes
- Self type
-
JsonMatch.type
Attributes
- Companion
- class
- Source
- JsonPatch.scala
- Supertypes
- Self type
-
JsonPatch.type
An untyped patch that operates on Json values. Patches are composable and can be applied with different failure handling modes.
An untyped patch that operates on Json values. Patches are composable and can be applied with different failure handling modes.
Value parameters
- ops
-
The sequence of patch operations to apply
Attributes
- Companion
- object
- Source
- JsonPatch.scala
- Supertypes
The reader to parse JSON input iteratively.
The reader to parse JSON input iteratively.
Value parameters
- bbuf
-
the byte buffer with JSON input
- buf
-
the internal buffer with JSON input
- charBuf
-
the internal char buffer for parsed strings
- config
-
the JSON reader configuration
- head
-
the head position in the internal buffer
- in
-
the input stream with JSON input
- markNum
-
the number of mark positions in the stack
- marks
-
the stack of mark positions
- maxTop
-
a maximum offset of the stack top
- stack
-
a pre-allocated stack of registers
- tail
-
the tail position in the internal buffer
- top
-
an offset of the stack top
- totalRead
-
the total number of read bytes
Attributes
- Companion
- object
- Source
- JsonReader.scala
- Supertypes
Attributes
- Companion
- class
- Source
- JsonReader.scala
- Supertypes
- Self type
-
JsonReader.type
Attributes
- Companion
- trait
- Source
- JsonSchema.scala
- Supertypes
- Self type
-
JsonSchema.type
A JSON Schema 2020-12 representation.
A JSON Schema 2020-12 representation.
This sealed trait provides a complete model of JSON Schema with:
- Boolean schemas (
Trueaccepts all,Falserejects all) - Full schema objects with all standard vocabularies
- Round-trip JSON serialization via
toJson/fromJson - Validation via
checkmethod returning accumulated errors - Combinators (
&&for allOf,||for anyOf,!for not)
Attributes
- Companion
- object
- Source
- JsonSchema.scala
- Supertypes
- Known subtypes
Represents the "type" keyword values in JSON Schema.
Represents the "type" keyword values in JSON Schema.
Note: This is distinct from JsonType which represents runtime JSON value types. JSON Schema's type keyword includes "integer" as a distinct type, while runtime JSON only has "number" for all numeric values.
Attributes
- Companion
- object
- Source
- JsonSchemaType.scala
- Supertypes
- Known subtypes
Attributes
- Companion
- trait
- Source
- JsonSchemaType.scala
- Supertypes
- Self type
-
JsonSchemaType.type
A wrapper around Either[SchemaError, Chunk[Json]] that provides fluent chaining for JSON navigation and querying operations.
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
- Supertypes
Attributes
- Companion
- class
- Source
- JsonSelection.scala
- Supertypes
- Self type
-
JsonSelection.type
A sealed trait representing the type of a JSON value.
A sealed trait representing the type of a JSON value.
This is used by MergeStrategy to make decisions about recursion without needing access to the actual JSON values.
Each case provides two type members:
Type: The corresponding Json subtype (e.g.,Json.Object)Unwrap: The underlying Scala type of the value (e.g.,Chunk[(String, Json)])
Attributes
- Companion
- object
- Source
- JsonType.scala
- Supertypes
- Known subtypes
Attributes
- Companion
- trait
- Source
- JsonType.scala
- Supertypes
- Self type
-
JsonType.type
Attributes
- Companion
- class
- Source
- JsonWriter.scala
- Supertypes
- Self type
-
JsonWriter.type
A writer for iterative serialization of JSON keys and values.
A writer for iterative serialization of JSON keys and values.
Value parameters
- bbuf
-
a byte buffer for writing JSON data
- buf
-
an internal buffer for writing JSON data
- comma
-
a flag indicating if comma should precede the next element
- config
-
a writer configuration
- count
-
the current position in the internal buffer
- disableBufGrowing
-
a flag indicating if growing of the internal buffer is disabled
- indention
-
the current indention level
- limit
-
the last position in the internal buffer
- maxTop
-
a maximum offset of the stack top
- out
-
the output stream for writing JSON data
- stack
-
a pre-allocated stack of registers
- top
-
an offset of the stack top
Attributes
- Companion
- object
- Source
- JsonWriter.scala
- Supertypes
Strategy for merging two JSON values.
Strategy for merging two JSON values.
A MergeStrategy is a function (DynamicOptic, Json, Json) => Json that determines how to merge two JSON values at a given path. The recurse method controls whether the merge driver should descend into containers (objects/arrays) or call apply directly.
When recurse returns true for a container type:
- Objects are merged by key (union of keys, recursive merge on shared keys)
- Arrays are merged by index (union of indices, recursive merge on shared indices)
When recurse returns false, apply is called with the container values directly.
Attributes
- Companion
- object
- Source
- MergeStrategy.scala
- Supertypes
- Known subtypes
Attributes
- Companion
- trait
- Source
- MergeStrategy.scala
- Supertypes
- Self type
-
MergeStrategy.type
Attributes
- Companion
- class
- Source
- JsonSchema.scala
- Supertypes
- Self type
-
NonNegativeInt.type
Non-negative integer (>= 0). Used for minLength, maxLength, minItems, etc.
Non-negative integer (>= 0). Used for minLength, maxLength, minItems, etc.
Attributes
- Companion
- object
- Source
- JsonSchema.scala
- Supertypes
Attributes
- Source
- NonNegativeIntCompanionVersionSpecific.scala
- Supertypes
- Known subtypes
-
object NonNegativeInt
Strictly positive number (> 0). Used for multipleOf.
Strictly positive number (> 0). Used for multipleOf.
Attributes
- Companion
- object
- Source
- JsonSchema.scala
- Supertypes
Attributes
- Companion
- class
- Source
- JsonSchema.scala
- Supertypes
- Self type
-
PositiveNumber.type
Attributes
- Source
- PositiveNumberCompanionVersionSpecific.scala
- Supertypes
- Known subtypes
-
object PositiveNumber
Attributes
- Companion
- class
- Source
- ReaderConfig.scala
- Supertypes
- Self type
-
ReaderConfig.type
Configuration for zio.blocks.schema.json.JsonReader that contains flags for tuning of preferred sizes for internal buffers that are created on the reader instantiation and reused in runtime for parsing of messages. All configuration params already initialized by recommended default values, but in some cases they should be altered for performance reasons:
Configuration for zio.blocks.schema.json.JsonReader that contains flags for tuning of preferred sizes for internal buffers that are created on the reader instantiation and reused in runtime for parsing of messages. All configuration params already initialized by recommended default values, but in some cases they should be altered for performance reasons:
- increase preferred size of an internal byte buffer for parsing from java.io.InputStream or java.nio.ByteBuffer to reduce allocation rate of grown and then reduced buffers during parsing of large (>32Kb) numbers (including stringified), raw values, or ADT instances with the discriminator field doesn't appear at the beginning of the JSON object
- increase the preferred size of an internal char buffer to reduce the allocation rate of grown and then reduced buffers when large (>4Kb) string instances
Value parameters
- checkForEndOfInput
-
a flag to check and raise an error if some non-whitespace bytes are detected after successful parsing of the value
- maxBufSize
-
a max size (in bytes) of an internal byte buffer when parsing from java.io.InputStream or java.nio.ByteBuffer
- maxCharBufSize
-
a max size (in chars) of an internal char buffer for parsing of string values
- preferredBufSize
-
a preferred size (in bytes) of an internal byte buffer when parsing from java.io.InputStream or java.nio.ByteBuffer
- preferredCharBufSize
-
a preferred size (in chars) of an internal char buffer for parsing of string values
Attributes
- Companion
- object
- Source
- ReaderConfig.scala
- Supertypes
- Known subtypes
-
object ReaderConfig
Attributes
- Companion
- class
- Source
- JsonSchema.scala
- Supertypes
- Self type
-
RegexPattern.type
ECMA-262 regular expression pattern.
Attributes
- Companion
- object
- Source
- JsonSchemaType.scala
- Supertypes
- Known subtypes
Attributes
- Companion
- trait
- Source
- JsonSchemaType.scala
- Supertypes
- Self type
-
SchemaType.type
URI-Reference per RFC 3986 (may be relative).
URI-Reference per RFC 3986 (may be relative).
Attributes
- Companion
- object
- Source
- JsonSchema.scala
- Supertypes
Attributes
- Companion
- class
- Source
- JsonSchema.scala
- Supertypes
- Self type
-
UriReference.type
Options for JSON Schema validation behavior.
Options for JSON Schema validation behavior.
Value parameters
- validateFormats
-
When true, the
formatkeyword is validated (format assertion vocabulary). When false,formatis treated as an annotation only (default per JSON Schema 2020-12).
Attributes
- Companion
- object
- Source
- JsonSchema.scala
- Supertypes
Attributes
- Companion
- class
- Source
- JsonSchema.scala
- Supertypes
- Self type
-
ValidationOptions.type
Attributes
- Companion
- class
- Source
- WriterConfig.scala
- Supertypes
- Self type
-
WriterConfig.type
Configuration for zio.blocks.schema.json.JsonWriter that contains params for formatting of output JSON and for tuning of preferred size for internal byte buffer that is created on the writer instantiation and reused in runtime for serialization of messages using any type of output except heap byte buffers supplied as arguments. All configuration params already initialized to default values, but in some cases they should be altered:
Configuration for zio.blocks.schema.json.JsonWriter that contains params for formatting of output JSON and for tuning of preferred size for internal byte buffer that is created on the writer instantiation and reused in runtime for serialization of messages using any type of output except heap byte buffers supplied as arguments. All configuration params already initialized to default values, but in some cases they should be altered:
- turn on pretty printing by specifying of an indention step that is greater than 0
- turn on escaping of Unicode characters to serialize with only ASCII characters
- increase the preferred size of an internal byte buffer to reduce the allocation rate of grown and then reduced internal buffers when the serialized output size is greater than 32Kb
Value parameters
- escapeUnicode
-
a flag to turn on hexadecimal escaping of all non-ASCII chars
- indentionStep
-
a size of indention for pretty-printed formatting or 0 for compact output
- preferredBufSize
-
a preferred size (in bytes) of an internal byte buffer when writing to any type of output except pre-allocated byte arrays or heap byte buffers supplied as arguments
Attributes
- Companion
- object
- Source
- WriterConfig.scala
- Supertypes
- Known subtypes
-
object WriterConfig
Extensions
Extensions
Attributes
- Source
- package.scala