jsons
Serialize and deserialize Python objects to and from JSON with no boilerplate
Repository Health
Technical Analysis
jsons is a Python library for turning Python objects into dicts or JSON strings and back again, with no changes required to your classes. It works out of the box with dataclasses, attrs classes, and plain old Python objects, inferring structure from type hints so serialization and deserialization stay declarative.
The API is intentionally tiny — jsons.dump to serialize and jsons.load to deserialize — while remaining easily customizable and extendable through registered serializers and deserializers. It understands typing generics like List[Tuple[A, B]], so nested and container types round-trip correctly.
What You Get
- Serialization of Python objects to dicts or JSON strings via
jsons.dump - Deserialization back into typed instances via
jsons.load - Zero-change support for dataclasses, attrs classes, and plain Python objects
- Handling of
typinggenerics likeList[Tuple[A, B]]for nested structures - Custom serializers and deserializers you can register to extend behavior
- Built-in handling of common types such as datetime with ISO formatting
Common Use Cases
- Converting dataclass instances to JSON for API responses or storage
- Reconstructing typed Python objects from incoming JSON payloads
- Round-tripping nested object graphs described purely by type hints
- Adding custom serialization rules for domain-specific types
Under The Hood
Architecture - jsons maintains registries of serializer and deserializer functions keyed by type. dump walks an object, looks up the serializer for each attribute’s runtime type, and recurses to produce a plain dict/JSON-compatible structure; load does the inverse, using the target class’s type hints (and any typing generic parameters) to pick deserializers and rebuild typed instances. A fork_inst mechanism lets you create isolated configurations so custom (de)serializers don’t leak across use sites.
Tech Stack - The package is pure Python with no hard runtime dependencies, distributed on PyPI and documented on Read the Docs. It integrates natively with the standard library’s dataclasses and the third-party attrs library, and relies heavily on the typing module for structural information.
Code Quality - The project has code coverage via Codecov and historically used Scrutinizer for quality scoring. It is mature (created 2018, 15 releases) but currently low-activity, with recent changelog entries focused on edge-case bugfixes such as datetime parsing.
API Design - The public API is deliberately minimal and symmetric — dump/load mirror each other — which makes the common case trivial while extension points (registering custom serializers, forked instances) remain available for advanced needs. Reliance on type hints means correct annotations are essential; ambiguous or missing hints are the main source of friction.