Dumping
Dump the model to a data format. Supports nested items.
JSON
Everyone's favorite data type.
from exacting import Exact
class Money(Exact):
swag: bool
money = Money(swag=True)
json = money.exact_as_json()
print(json) # {"swag": true}
data = Money.exact_from_json(json)
print(data) # Money(swag=True)
Side note, you can actually load from JSON with comments (jsonc). Just disable strict mode via strict=False
.
json = """{
"swag": /* false */ true, // yeah, trailing commas
}"""
data = Money.exact_from_json(json, strict=False)
print(data) # Money(swag=True)
Bytes
Exacting uses rkyv for serialization/deserialization.
Lazy developer warning
This thingy is experimental. It's not yet ready for production, y'know.