This library provides a simple API for encoding and decoding [dataclasses](https://www.python.org/dev/peps/pep-0557/) to and from JSON.
It's recursive (see caveats below), so you can easily work with nested dataclasses.
In addition to the supported types in the [py to JSON table](https://docs.python.org/3/library/json.html#py-to-json-table), any arbitrary
[Collection](https://docs.python.org/3/library/collections.abc.html#collections.abc.Collection) type is supported (they are encoded into JSON arrays, but decoded into the original collection types).
**The [latest release](https://github.com/lidatong/dataclasses-json/releases/latest) is compatible with both Python 3.7 and Python 3.6 (with the dataclasses backport).**
## Quickstart
`pip install dataclasses-json`
```python
my_dataclass_instance.to_json()
MyDataClass.from_json(some_json_string)
```
```python
from dataclasses import dataclass
from dataclasses_json import DataClassJsonMixin
@dataclass(frozen=True)
class Minion():
name: str
@dataclass(frozen=True)
class Boss(DataClassJsonMixin):
minions: List[Minion]
boss = Boss([Minion('evil minion'), Minion('very evil minion')])
boss_json = """
{
"minions": [
{
"name": "evil minion"
},
{
"name": "very evil minion"
}
]
}
""".strip()
assert boss.to_json(indent=4) == boss_json
assert Boss.from_json(boss_json) == boss
```
## Caveats
Data Classes that contain forward references (e.g. recursive dataclasses) are not currently supported.
Metadata
Release files for dataclasses-json 0.0.10
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 |
|---|---|---|---|---|
| dataclasses-json-0.0.10.tar.gz | 3.6 kB | Without provenance | Details for dataclasses-json-0.0.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dataclasses_json-0.0.10-py3-none-any.whl | Python 3 | none | any | Details for dataclasses_json-0.0.10-py3-none-any.whl |
Total release size: 9.2 kB
Release files / dataclasses-json-0.0.10.tar.gz
| Download URL | dataclasses-json-0.0.10.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
786acf7d87e97966e96f93a9505fe4981923755012f312b6ca8629e0b04548d4
|
|
BLAKE2b-256 checksum How to use checksums |
1045ef169e634478265f2aee4c96bb65cdea7403dc3f662fb628d4dfd51967ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0
|
Release files / dataclasses_json-0.0.10-py3-none-any.whl
| Download URL | dataclasses_json-0.0.10-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ac613342b321d63130f58f0bc5512b2ae6b76cbd74c722aa0758f5d38edc71a9
|
|
BLAKE2b-256 checksum How to use checksums |
41ebe78976ce67460d6f99a7482a0ad61d5fdc4a4dcaf52052c2c689a531d028
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0
|
Security for dataclasses-json 0.0.10
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.