examples/

directory
v0.6.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2026 License: MIT

README ΒΆ

Examples

Practical examples demonstrating JSON Schema validation and unmarshaling with the new separated workflow.

Available Examples

🎯 Basic

Simple validation example showing valid and invalid data handling.

πŸ—οΈ Struct Validation

Direct struct validation without JSON marshaling for optimal performance.

πŸ”„ Multiple Input Types

Handle different data types (JSON bytes, maps, structs) with type-specific methods.

πŸ“¦ Unmarshaling

Validation + unmarshaling workflow with default value application.

βš™οΈ Dynamic Defaults

Dynamic default value generation using registered functions (e.g., timestamps, UUIDs).

πŸ“‹ Custom Formats

Custom format validation using registered functions.

⚠️ Error Handling

Comprehensive error handling patterns and validation failure management.

🌍 Internationalization

Multilingual error messages using Chinese (zh-Hans) and English locales with ToLocalizeList.

🌐 Multilingual Errors

Advanced multilingual error handling with GetDetailedErrors method supporting 9 languages.

πŸ—οΈ Constructor

Schema creation using fluent constructor API with keywords and validation.

Running Examples

# Run any example
cd <example-directory>
go run main.go

# Or run from project root (for single-file examples)
go run examples/<example-name>/main.go

# For dynamic defaults example
cd examples/dynamic-defaults
go run dynamic_defaults.go

Directories ΒΆ

Path Synopsis
Package main demonstrates basic usage of the jsonschema library.
Package main demonstrates basic usage of the jsonschema library.
Package main demonstrates constructor usage of the jsonschema library.
Package main demonstrates constructor usage of the jsonschema library.
Package main demonstrates custom-formats usage of the jsonschema library.
Package main demonstrates custom-formats usage of the jsonschema library.
Package main demonstrates dynamic default value generation with the jsonschema library.
Package main demonstrates dynamic default value generation with the jsonschema library.
Package main demonstrates error-handling usage of the jsonschema library.
Package main demonstrates error-handling usage of the jsonschema library.
Package main demonstrates i18n usage of the jsonschema library.
Package main demonstrates i18n usage of the jsonschema library.
Package main demonstrates multilingual-errors usage of the jsonschema library.
Package main demonstrates multilingual-errors usage of the jsonschema library.
Package main demonstrates multiple-input-types usage of the jsonschema library.
Package main demonstrates multiple-input-types usage of the jsonschema library.
Package main demonstrates struct-validation usage of the jsonschema library.
Package main demonstrates struct-validation usage of the jsonschema library.
Package main demonstrates unmarshaling usage of the jsonschema library.
Package main demonstrates unmarshaling usage of the jsonschema library.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL