ExJsonschema.ErrorFormatter (ExJsonschema v0.1.17)

View Source

Provides 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.

Functions

Returns all available output formats.

Formats validation errors in the specified format.

Types

format()

@type format() ::
  human_format()
  | json_format()
  | table_format()
  | markdown_format()
  | llm_format()

All supported output formats for error formatting.

format_option()

@type format_option() ::
  {:color, boolean()}
  | {:pretty, boolean()}
  | {:compact, boolean()}
  | {:max_errors, pos_integer()}
  | {:heading_level, 1..6}
  | {:include_toc, boolean()}
  | {:include_schema_context, boolean()}
  | {:structured, boolean()}

format_options()

@type format_options() :: [format_option()]

human_format()

@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.

json_format()

@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.

llm_format()

@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.

markdown_format()

@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.

table_format()

@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

available_formats()

@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

format(errors, format, options \\ [])

Formats validation errors in the specified format.

Arguments

  • errors - List of ValidationError structs
  • format - Output format (see available_formats/0 for 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