This directory contains runnable Python examples demonstrating all the features of Kajson. Each example is self-contained and can be run independently.
- 01_basic_pydantic_serialization.py - Basic Pydantic model with datetime serialization
- 08_readme_basic_usage.py - Shows the problem with standard JSON and how Kajson solves it
- 02_nested_models_mixed_types.py - BlogPost with Comment models, timedelta support
- 09_readme_complex_nested.py - Complex nested structures with metadata
- 03_custom_classes_json_hooks.py - Point class using
__json_encode__/__json_decode__hooks - 11_readme_custom_hooks.py - Vector class with custom JSON hooks
- 04_registering_custom_encoders.py - Register Decimal and Path type encoders
- 10_readme_custom_registration.py - Advanced custom type registration
- 05_mixed_types_lists.py - Lists containing different types (Task, datetime, dict, list, time)
- 12_readme_mixed_types.py - Complex mixed-type data structures with timedelta
- 06_error_handling_validation.py - Pydantic validation error handling
- 13_readme_error_handling.py - Clear error messages for validation failures
- 07_drop_in_replacement.py - Using Kajson as a drop-in replacement for standard json
- 14_dynamic_class_registry.py - When and why to use the class registry for dynamic classes
- 15_pydantic_subclass_polymorphism.py - Polymorphism with Pydantic models: subclass preservation during serialization
Each example can be run independently:
# Run a specific example
python examples/01_basic_pydantic_serialization.py
# Or run from the examples directory
cd examples
python 01_basic_pydantic_serialization.pyEach example includes:
- ✅ Clear success indicators
- 🔍 Type checking demonstrations
- 📊 Before/after comparisons
- 💡 Explanatory comments
All examples require:
- Python 3.10+
- kajson (installed in development mode)
- pydantic (for BaseModel examples)
The examples use only standard library imports plus kajson and pydantic, making them easy to run and understand.