JsonMatch

zio.blocks.schema.json.JsonMatch
object JsonMatch

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
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
JsonMatch.type

Members list

Value members

Concrete methods

def matches(pattern: SchemaRepr, json: Json): Boolean

Tests whether a Json value matches a SchemaRepr pattern.

Tests whether a Json value matches a SchemaRepr pattern.

Value parameters

json

the JSON value to check

pattern

the schema pattern to match against

Attributes

Returns

true if the JSON matches the pattern, false otherwise

Source
JsonMatch.scala