I have JSON input like this:
{
"accountID": "001-002-003-004",
"accountClass": "Primary",
"id": "1-2",
"openTime": "2019-12-21T02:12:17.122Z",
"priceDifference": "0.12345",
}
I would like to deserialise it into a Python object in a way similar to how serde
from Rust works.
I would like to define a class like this:
@dataclass
class MyClass:
accountID: str
accountClass: str
id: str
openTime: str
priceDifference: float
After loading the JSON data what is the best way to serialise it into that classes object?
I know I can use kwargs for that like this:
MyClass(**json_data)
But one of the pains here is that the names would have to match therefore I cannot have snake case for names of the fields in my class (or maybe there is a way to rename those, but I dont know how).
Is there a better way to do that? Also is there a way in which I could keep the snake case naming for my class without changing the names of the JSON fields?