honk
Types
pub type ValidationError =
errors.ValidationError
Values
pub fn dynamic_to_json(
dyn: dynamic.Dynamic,
) -> Result(json.Json, errors.ValidationError)
Convert a Dynamic value to Json
This is useful when parsing JSON strings with json.parse(str, decode.dynamic)
and then needing to convert to Json for validation.
Example
use dyn <- result.try(json.parse(json_str, decode.dynamic))
use json_val <- result.try(honk.dynamic_to_json(dyn))
honk.validate([json_val])
pub fn main() -> Nil
CLI entry point for the honk lexicon validator
Usage:
gleam run -m honk check
pub fn parse_json_string(
json_str: String,
) -> Result(json.Json, errors.ValidationError)
Parse a JSON string and convert to Json for validation
This is a convenience function that combines json.parse() and dynamic_to_json().
It’s useful when you have JSON stored as strings (e.g., in a database) and want
to validate it with honk.
Example
use json_val <- result.try(honk.parse_json_string(stored_json))
honk.validate([json_val])
pub fn parse_json_strings(
json_strs: List(String),
) -> Result(List(json.Json), errors.ValidationError)
Parse multiple JSON strings and convert to Json for validation
This is a convenience function for batch parsing JSON strings.
Example
use json_vals <- result.try(honk.parse_json_strings(stored_jsons))
honk.validate(json_vals)
pub fn validate(
lexicons: List(json.Json),
) -> Result(Nil, dict.Dict(String, List(String)))
Validates lexicon documents
Validates lexicon structure (id, defs) and ALL definitions within each lexicon. Each definition in the defs object is validated according to its type.
Returns Ok(Nil) if all lexicons and their definitions are valid. Returns Error with a map of lexicon ID to list of error messages. Error messages include the definition name (e.g., “lex.id#defName: error”).
pub fn validate_record(
lexicons: List(json.Json),
collection: String,
record: json.Json,
) -> Result(Nil, errors.ValidationError)
Validates a single data record against a collection schema
pub fn validate_string_format(
value: String,
format: types.StringFormat,
) -> Result(Nil, String)
Validates a string value against a specific format