Skip to main content
Version: 1.1.0

Welcome to Pedantigo

Type-safe JSON validation for Go, inspired by Pydantic

Pedantigo brings Pydantic's elegant validation patterns to Go with a reflection-based design that feels natural in the Go ecosystem.

Why Pedantigo?

Pedantigo was built while developing smrut.ai, where reliable JSON validation is critical for AI agent interactions.

When building Go applications that consume JSON from external sources (APIs, AI agents, user input), you need validation that's:

  • Type-safe: Catch errors at unmarshal time, not deep in your application
  • Declarative: Define rules alongside your struct fields with tags
  • Fast: Cached JSON schemas deliver 240x performance gains
  • Production-ready: Battle-tested constraints covering email, URLs, regex, ranges, and more

Quick Example

package main

import (
"fmt"
"github.com/smrutai/pedantigo"
)

type User struct {
Email string `json:"email" pedantigo:"required,email"`
Age int `json:"age" pedantigo:"min=18,max=120"`
Role string `json:"role" pedantigo:"oneof=admin user guest"`
}

func main() {
jsonData := []byte(`{"email": "user@example.com", "age": 25, "role": "admin"}`)

// Parse, validate, and unmarshal in one call
user, err := pedantigo.Unmarshal[User](jsonData)
if err != nil {
fmt.Println("Validation failed:", err)
return
}

fmt.Printf("Welcome %s!\n", user.Email)
}

Two Ways to Validate

Pedantigo offers two API styles to match your use case:

Best for most use cases - Global schema cache, minimal boilerplate:

// Parse JSON + validate
user, err := pedantigo.Unmarshal[User](jsonData)

// Create from JSON/map/struct with validation
user, err := pedantigo.NewModel[User](input)

// Validate existing struct
err := pedantigo.Validate[User](existingUser)

// Get cached JSON Schema
schema := pedantigo.Schema[User]()

The Simple API uses a global schema cache that's automatically managed. Perfect for typical validation workflows.

Features at a Glance

FeatureDescription
100+ Built-in ConstraintsEmail, URL, regex, ranges, string length, array constraints, and more
JSON Schema GenerationAuto-generate JSON schemas from Go structs with validation metadata
240x PerformanceFirst-call schema caching delivers sub-100ns lookups vs ~10ms generation
Streaming ValidationValidate partial JSON for progressive parsing scenarios
Discriminated UnionsType-safe union handling with discriminator fields
Cross-Field ValidationImplement Validate() interface for complex multi-field rules
Custom ValidatorsRegister your own constraints globally or per-validator
Zero DependenciesOnly uses invopop/jsonschema + Go standard library

What You'll Learn

This documentation covers everything from basic validation to advanced patterns:

Ready to start?

Head to Installation to add Pedantigo to your project, or jump to Quick Start for a guided tutorial.