Liking cljdoc? Tell your friends :D

s-exp.legba.json-schema

JSON Schema validation utilities. Provides helpers to load, cache, and validate JSON Schemas

JSON Schema validation utilities.
Provides helpers to load, cache, and validate JSON Schemas
raw docstring

schemaclj

(schema schema-uri
        &
        {:as _opts
         :keys [schema-validator-config]
         :or {schema-validator-config schema-validator-config}})

Loads and builds a JSON Schema validator instance from a URI or file path.

Arguments:

  • schema-uri (string): Location of the JSON Schema (file:/..., http:/..., classpath:/..., etc)

  • :schema-validator-config (optional): Custom SchemaValidatorsConfig (default: this namespace's schema-validator-config).

Returns:

An instance of the JSON Schema validator (com.networknt.schema.JsonSchema). This object can be reused to validate multiple values or payloads.

Example: (schema "classpath:///tmp/foo.schema.json") (schema "file:///data/schema/bar.json") (schema "https://schemas.org/example.schema.json")

Loads and builds a JSON Schema validator instance from a URI or file path.

Arguments:
  - `schema-uri` (string): Location of the JSON Schema (file:/..., http:/...,
classpath:/..., etc)

  - `:schema-validator-config` (optional): Custom
`SchemaValidatorsConfig` (default: this namespace's
`schema-validator-config`).

Returns:

  An instance of the JSON Schema validator (`com.networknt.schema.JsonSchema`).
  This object can be reused to validate multiple values or payloads.

Example:
  (schema "classpath:///tmp/foo.schema.json")
  (schema "file:///data/schema/bar.json")
  (schema "https://schemas.org/example.schema.json")
raw docstring

schema-validator-configclj

Default reusable SchemaValidatorsConfig instance.

This configures the validator to:

  • Enable JSON Schema reference preloading and caching
  • Enable format assertions (per the JSON Schema spec)
  • Set maximum reference nesting depth to 40
  • Handle nullable fields correctly
  • Use JSON_PATH for error paths in validation results

This config can be reused for schema load/validation for performance and consistency.

Default reusable `SchemaValidatorsConfig` instance.

This configures the validator to:
- Enable JSON Schema reference preloading and caching
- Enable format assertions (per the JSON Schema spec)
- Set maximum reference nesting depth to 40
- Handle `nullable` fields correctly
- Use `JSON_PATH` for error paths in validation results

This config can be reused for schema load/validation for performance and consistency.
raw docstring

validate!clj

(validate! schema
           val
           &
           {:as _opts
            :keys [validation-result]
            :or {validation-result validation-result}})

Validates a value against a previously loaded or constructed schema.

Arguments:

  • schema: The schema object returned from schema
  • val: The input to validate. Can be a JsonNode or a JSON string.
  • :validation-result (optional): Override for the function used to extract validation errors (defaults to this namespace's validation-result).

Returns: A sequence of error maps (see validation-result), or nil if valid.

Example: (validate! myschema "{"foo":42}") (validate! myschema my-jackson-json-node)

Validates a value against a previously loaded or constructed schema.

Arguments:
  - `schema`: The schema object returned from `schema`
  - `val`: The input to validate. Can be a JsonNode or a JSON string.
  - `:validation-result` (optional): Override for the function used to extract
validation errors (defaults to this namespace's `validation-result`).

Returns:
  A sequence of error maps (see `validation-result`), or nil if valid.

Example:
  (validate! myschema "{"foo":42}")
  (validate! myschema my-jackson-json-node)
raw docstring

validation-resultclj

(validation-result r)

Extracts validation errors from a ValidationResult object.

Arguments:

  • r (ValidationResult): The result object returned by a validation call.

Returns: A sequence of maps, one for each validation error, containing:

  • :type: Error type string from validation
  • :path: JSON path to offending element
  • :error: Error code string
  • :message: Human-friendly error message Returns nil if the validation result contains no errors.
Extracts validation errors from a ValidationResult object.

Arguments:
  - `r` (ValidationResult): The result object returned by a validation call.

Returns:
  A sequence of maps, one for each validation error, containing:
  - `:type`: Error type string from validation
  - `:path`: JSON path to offending element
  - `:error`: Error code string
  - `:message`: Human-friendly error message
  Returns `nil` if the validation result contains no errors.
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close