ExJsonschema.ErrorFormatter (ExJsonschema v0.1.17)
View SourceProvides utilities for formatting JSON Schema validation errors in multiple output formats.
Supports five output formats:
:human- Human-readable text format with colors and suggestions:json- Structured JSON format for programmatic use:table- Tabular format for easy scanning of multiple errors:markdown- Markdown format for documentation and reports:llm- LLM-optimized format for AI assistant consumption
Examples
# Format errors for human consumption
ErrorFormatter.format(errors, :human)
# Format as JSON with pretty printing
ErrorFormatter.format(errors, :json, pretty: true)
# Format as compact table
ErrorFormatter.format(errors, :table, compact: true)
# Format as markdown for documentation
ErrorFormatter.format(errors, :markdown)
# Format for LLM consumption
ErrorFormatter.format(errors, :llm)Formatting Options
Each format supports specific options:
Human Format Options
color: boolean()- Enable/disable ANSI color codes (default: true)max_errors: pos_integer()- Maximum errors to display (default: 20)
JSON Format Options
pretty: boolean()- Pretty print JSON with indentation (default: false)
Table Format Options
compact: boolean()- Use compact table layout (default: false)max_errors: pos_integer()- Maximum errors to display (default: 50)
Markdown Format Options
heading_level: 1..6- Base heading level for sections (default: 2)include_toc: boolean()- Include table of contents (default: false)max_errors: pos_integer()- Maximum errors to display (default: 100)
LLM Format Options
include_schema_context: boolean()- Include schema path context (default: true)structured: boolean()- Use structured format vs prose (default: false)max_errors: pos_integer()- Maximum errors to display (default: 20)
Summary
Types
All supported output formats for error formatting.
Human-readable text format with ANSI colors, context, and suggestions.
Structured JSON format for programmatic use and API responses.
LLM-optimized format designed for AI assistant consumption.
Markdown format for documentation, reports, and rich text output.
ASCII table format for comparing multiple errors side-by-side.
Types
@type format() :: human_format() | json_format() | table_format() | markdown_format() | llm_format()
All supported output formats for error formatting.
@type format_options() :: [format_option()]
@type human_format() :: :human
Human-readable text format with ANSI colors, context, and suggestions.
Ideal for console applications, terminal output, and developer feedback. Supports color customization and error count limits.
@type json_format() :: :json
Structured JSON format for programmatic use and API responses.
Perfect for APIs, structured logging, and machine processing. Supports pretty-printing and clean null field handling.
@type llm_format() :: :llm
LLM-optimized format designed for AI assistant consumption.
Optimized for large language models with structured or prose output. Includes clear context separation and actionable information.
@type markdown_format() :: :markdown
Markdown format for documentation, reports, and rich text output.
Great for README files, documentation generation, and web display. Supports heading levels, table of contents, and proper escaping.
@type table_format() :: :table
ASCII table format for comparing multiple errors side-by-side.
Excellent for reports, debugging sessions, and scanning large error lists. Supports compact layout and automatic column sizing.
Functions
@spec available_formats() :: [format()]
Returns all available output formats.
Examples
iex> formats = ExJsonschema.ErrorFormatter.available_formats()
iex> :human in formats
true
iex> :markdown in formats
true
@spec format([ExJsonschema.ValidationError.t()], format(), format_options()) :: String.t()
Formats validation errors in the specified format.
Arguments
errors- List of ValidationError structsformat- Output format (seeavailable_formats/0for supported formats)options- Format-specific options (optional)
Examples
iex> errors = [%ExJsonschema.ValidationError{
...> instance_path: "/name",
...> message: "is not of type string"
...> }]
iex> result = ExJsonschema.ErrorFormatter.format(errors, :human)
iex> is_binary(result)
true