json-tag
Python support for JSON#.
Configures pydantic to use the JSON# convention.
Install
pip install json-tag
Usage
Define your types:
class Circle(JsonTagModel):
radius: float
class Rectangle(JsonTagModel):
width: float
height: float
Shape = tagged_union(Circle, Rectangle)
Serialize:
circle = Circle(radius=4.0)
circle.to_json()
# {"#type":"Circle","radius":4}
Deserialize:
from pydantic import TypeAdapter
shape = TypeAdapter(Shape).validate_json('{"#type":"Circle","radius":4}')
# Circle(radius=4.0)
Custom tag names via __json_tag_name__ class variable:
class PersonalVehicle(JsonTagModel):
__json_tag_name__ = "Car"
make: str
API
| Export | Description |
|---|---|
JsonTagModel |
Base model — subclasses get #type automatically |
tagged_union(*types) |
Create a discriminated union with #type |
TYPE_FIELD |
The "#type" constant |
Metadata
Release files for json-tag 1.0.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 |
|---|---|---|---|---|
| json_tag-1.0.0.tar.gz | 3.9 kB | Without provenance | Details for json_tag-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| json_tag-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for json_tag-1.0.0-py3-none-any.whl |
Total release size: 7.3 kB
Release files / json_tag-1.0.0.tar.gz
| Download URL | json_tag-1.0.0.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6cfde2eee13ea0b58c7f4eed6cc59f1f68e603e117797fc3404b584eb745127
|
|
BLAKE2b-256 checksum How to use checksums |
8e9454676b693d620a0b4244cdcdcc82012f3c1ebe0ec77a82b4f697745c90a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / json_tag-1.0.0-py3-none-any.whl
| Download URL | json_tag-1.0.0-py3-none-any.whl |
|---|---|
| Size | 3.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f33c3536bb9a9b8daf646aec53738af9a8d8f459e5ba1d3486c0e19666b9745c
|
|
BLAKE2b-256 checksum How to use checksums |
c5151df4d59c16c34c73b5d730638a32e953666a4d98edb61c5f32e4eff8ee0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for json-tag 1.0.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.