All Questions
Tagged with python-attrs json
6
questions
2
votes
2
answers
2k
views
serializing to JSON an array of data classes
I have an array of data classes I need to serialize to JSON. I wrap the list in a class (Persons)
@attrs.frozen
class Person:
name: str
age: int
grades: Dict[str, int]
@attrs.define
class ...
2
votes
2
answers
2k
views
Python attrs/cattrs serializing a dict using frozen attrs classes as the dict keys
I would like to structure and unstructure an attrs object, which includes dict fields that use simple frozen attrs for the dict keys. This works very well for objects created at runtime, but the ...
1
vote
1
answer
1k
views
Structure JSON to an `attrs` class with extra fields using `cattrs`?
I would like to structure JSON to an attrs class that allows for extra fields using cattrs. cattrs by default will ignore extra fields and if forbid_extra_keys=True an error is raised when extra ...
2
votes
1
answer
3k
views
Unstructuring a complex class with cattrs
I'm having problems using attrs/cattrs to transform a custom dataclass to JSON format. My class has the form:
import attr
from datetime import datetime
from typing import Tuple, Set, Dict, FrozenSet
@...
0
votes
1
answer
3k
views
How to deserialize json with optional fields using attrs and cattrs
I want to deserialize MongoDB documents using attr and cattrs. Since noSQL has no fixed schema, I need to point somehow to the attr.ib-s that they could be missed, and not add them to the dict's ...
9
votes
1
answer
9k
views
Using attrs to turn JSONs into Python classes
I was wondering if it possible to use the attrs library to convert nested JSONs to Python class instances so that I can access attributes in that JSON via dot notation (object.attribute....