confuse-jsonschema
Convert JSON Schema to Confuse templates for seamless configuration validation.
Overview
confuse-jsonschema is a library that allows you to create a
Confuse template from a JSON schema.
This allows you to benefit from the advanced validation capabilities of
JSON schema for checking your configuration, while taking advantage of the
flexibility of confuse for configuration management.
Installation
pip install confuse-jsonschema
Quick Start
from confuse_jsonschema import to_template
import confuse
# Define your configuration schema
schema = {
"type": "object",
"properties": {
"server": {
"type": "object",
"properties": {
"host": {"type": "string", "default": "localhost"},
"port": {"type": "integer", "default": 8080}
},
"required": ["host"]
},
"database": {
"type": "object",
"properties": {
"url": {"type": "string"},
"timeout": {"type": "number", "default": 30.0}
},
"required": ["url"]
}
},
"required": ["server", "database"]
}
# Convert to Confuse template
template = to_template(schema)
# Use with Confuse
config = confuse.Configuration('myapp')
validated_config = config.get(template)
Supported JSON Schema Features
Fully Supported
Basic Types
string- converts tostror customSchemaStringwith constraintsinteger- converts tointor customSchemaIntegerwith constraintsnumber- converts tofloator customSchemaNumberwith constraintsboolean- converts toboolor default valuenull- converts toNoneor default value
Advanced Types
const- fixed constant valuesenum- choice from enumerated values usingconfuse.Choice- Multiple types (e.g.,
["string", "integer"]) - converts toconfuse.OneOf
Complex Types
object- converts to nested dictionary templatearray- converts toconfuse.SequenceorSchemaSequencewith constraints
String Constraints
minLength/maxLength- enforced viaSchemaStringpattern- regex validation viaSchemaStringformat- special formats likepath,uri-referenceconvert toconfuse.Filename
Numeric Constraints
minimum/maximum- inclusive bounds viaSchemaInteger/SchemaNumberexclusiveMinimum/exclusiveMaximum- exclusive boundsmultipleOf- divisibility validation
Array Constraints
minItems/maxItems- size validation viaSchemaSequenceuniqueItems- uniqueness validation viaSchemaSequenceitems- item type specification
Object Features
properties- property definitionsrequired- required properties (others becomeconfuse.Optional)default- default values
Logical Operators
anyOf- any schema can match usingconfuse.OneOfoneOf- exactly one schema must match usingconfuse.OneOfallOf- all schemas must match using customAllOftemplateif/then/else- basic conditional support
Partially Supported
References
$ref- basic placeholder support (returns genericconfuse.Template)- Limitation: No actual reference resolution implemented
- Workaround: Manually inline referenced schemas
Object Constraints
-
additionalProperties- recognized but not enforced- Limitation: Confuse templates use fixed dictionary structures
- Impact: Additional properties will be accepted without validation
-
patternProperties- recognized but not enforced- Limitation: Confuse doesn't support dynamic property validation based on key patterns
- Impact: Pattern-based property validation is ignored
Complex Logic
if/then/else- basic implementation- Limitation: Doesn't evaluate conditions; just uses
thenorelse - Impact: Conditional validation doesn't work properly
- Limitation: Doesn't evaluate conditions; just uses
Not Supported
Advanced JSON Schema Features
-
Property Dependencies
{ "dependencies": { "credit_card": ["billing_address"] } }
No concept of field interdependencies
-
Conditional Validation
{ "if": {"properties": {"type": {"const": "credit_card"}}}, "then": {"required": ["number", "cvv"]} }
Dynamic validation based on other field values isn't supported
-
Complex Array Validation
{ "prefixItems": [{"type": "string"}, {"type": "number"}], "items": false }
Confuse sequences validate all items uniformly
-
Property Name Validation
{ "propertyNames": {"pattern": "^[A-Za-z_][A-Za-z0-9_]*$"} }
No validation of dictionary key names
-
Format Validation
{"type": "string", "format": "email"}
Most JSON Schema formats aren't supported (only
pathanduri-reference) -
Schema Metadata
title,description,examples- ignored (no impact on validation)$id,$schema- ignoreddeprecated- ignored
Limitations
-
Configuration Layering Conflicts
- JSON Schema defines single validation rules
- Confuse merges multiple configuration sources
- Impact: Schema validation happens after configuration merging
-
Type Coercion Differences
- JSON Schema: strict type validation
- Confuse: automatic type coercion (e.g., string "123" → integer 123)
- Impact: Some invalid values might be accepted after coercion
-
Error Reporting
- JSON Schema: detailed validation error paths
- Confuse: simpler error messages
- Impact: Less precise error information for complex schemas
-
Runtime vs Static Validation
- JSON Schema: can validate any data structure
- Confuse: designed for configuration files with known structure
- Impact: Less flexibility for dynamic data validation
Examples
Simple Configuration
schema = {
"type": "object",
"properties": {
"app_name": {"type": "string", "default": "MyApp"},
"debug": {"type": "boolean", "default": False},
"port": {"type": "integer", "default": 3000}
}
}
template = to_template(schema)
Workarounds for Unsupported Features
# Instead of $ref, inline the schema
# Not supported:
schema_with_ref = {
"type": "object",
"properties": {
"user": {"$ref": "#/definitions/User"}
},
"definitions": {
"User": {
"type": "object",
"properties": {"name": {"type": "string"}}
}
}
}
# Use this instead:
schema_inlined = {
"type": "object",
"properties": {
"user": {
"type": "object",
"properties": {"name": {"type": "string"}}
}
}
}
Format Validation
# Most formats aren't supported - use pattern instead
# Not supported:
{"type": "string", "format": "email"}
# Use pattern instead:
{"type": "string", "pattern": "^[^@]+@[^@]+\\.[^@]+$"}
# Supported formats:
{"type": "string", "format": "path"} # → confuse.Filename
{"type": "string", "format": "uri-reference"} # → confuse.Filename
Development
Setup
git clone https://github.com/chmduquesne/confuse-jsonschema.git
cd confuse-jsonschema
pip install -e ".[dev]"
Running Tests
pytest
Code Formatting
black .
flake8
Publishing to PyPI
- Build the package:
python -m build
- Upload to PyPI:
python -m twine upload dist/*
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. .
Metadata
Release files for confuse-jsonschema 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| confuse_jsonschema-0.1.0.tar.gz | 21.0 kB | Without provenance | Details for confuse_jsonschema-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| confuse_jsonschema-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for confuse_jsonschema-0.1.0-py3-none-any.whl |
Total release size: 31.9 kB
Release files / confuse_jsonschema-0.1.0.tar.gz
| Download URL | confuse_jsonschema-0.1.0.tar.gz |
|---|---|
| Size | 21.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a006d091c214eb05a488fd12e5b94580e60d797dac85214113013257a7415950
|
|
BLAKE2b-256 checksum How to use checksums |
9695fc683b3c199e9e3225650a533b53a4f91981ef53860021f2487ff3dbb8e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / confuse_jsonschema-0.1.0-py3-none-any.whl
| Download URL | confuse_jsonschema-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
106d7a48c502326797c6faafe3e5b12cbc18087cb51d54459274de70d1aa4348
|
|
BLAKE2b-256 checksum How to use checksums |
08bc0fd374b81bcf609d8016265a99c61d36330215db4474f628a11665ea02fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for confuse-jsonschema 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.