JsonSchemaNif (JSON Schema NIF v0.1.1)

Provides functionality for validating JSON instances against JSON schemas.

This Elixir module interfaces with Rust-implemented functions via Rustler, leveraging Rust's performance for efficient JSON validation.

Summary

Functions

Validates a JSON instance against a JSON schema.

Functions

Link to this function

validate_json(instance, schema)

@spec validate_json(binary(), binary()) :: :ok | {:error, atom()}

Validates a JSON instance against a JSON schema.

This function is a wrapper for the Rust-implemented NIF (Native Implemented Function).

Parameters

  • instance: The JSON instance to be validated.
  • schema: The JSON schema against which the instance is validated.

Returns

Returns :ok if the JSON instance matches the schema, {:error, :violates_schema} if it violates the schema, or an appropriate error tuple for other failure modes.

Examples

iex> JsonSchemaNif.validate_json("{\"name\":\"John\"}", "{\"type\":\"object\"}")
:ok

iex> JsonSchemaNif.validate_json("{\"age\":30}", "{\"type\":\"string\"}")
{:error, :violates_schema}

Note

This function will raise an error if the NIF is not loaded, which typically indicates a compilation or deployment issue with the Rust code.