Registry / serialization / typing-json

typing-json

JSON →
library0.1.3pypypi✓ verified 82d ago

Type-aware Python JSON serialization and validation. Provides decorators and functions to encode/decode Python objects with type hints, with support for Union, Optional, and nested dataclasses. Current version 0.1.3, released 2023; low release cadence.

pip install typing-json
INSTALL
IMPORT
SIG · TYPING-JSON
T
typing-json
serializationpythonv0.1.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

dumps
from typing_json import dumps
from typing_json import to_json
loads
from typing_json import loads
dump
from typing_json import dump

Defines a dataclass with optional field, serializes to JSON, then deserializes back.

from dataclasses import dataclass from typing import Optional from typing_json import to_json, from_json @dataclass class Person: name: str age: int email: Optional[str] = None # Serialize person = Person('Alice', 30) json_str = to_json(person) print(json_str) # '{"name": "Alice", "age": 30, "email": null}' # Deserialize person2 = from_json(json_str, Person) print(person2) # Person(name='Alice', age=30, email=None)
Debug
Known issues
gotchaUnion types are only supported if the alternatives are distinct types (e.g., int vs str). If multiple types share the same base or are ambiguous (e.g., Union[int, float]), deserialization may fail or produce wrong type.
fix
Use explicit discriminators or avoid ambiguous Union types. For numbers, prefer the broader type (e.g., float).
affects: *
deprecatedThe function `to_json` defaults to `ensure_ascii=False`, which may produce non-ASCII characters. Future versions may change this.
fix
Always pass `ensure_ascii=True` if you need ASCII-only JSON, or rely on current default but be aware it might change.
affects: <0.2.0
gotchaNested dataclasses are supported, but only if all fields are serializable. If a field is a custom class without type hints, serialization fails silently or raises TypeError.
fix
Ensure all nested objects are dataclasses or have registered serializers. Use `@json` decorator from `typing_json` library (experimental) for plain classes.
affects: *
Upgrade
Version history
0.1.3latest on PyPI · released Dec 16, 2020
Audit
Dependencies
typing_extensionsrequiredRequired for compatibility with Python <3.10 (e.g., Literal, get_type_hints)
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
typing-json — pip install typing-json · libregistry