Closed julsas closed 3 years ago
It is always recommended that use the built-in method json
. For example in your case
obs = Observation(**json_data)
print(obs.json(indent=2))
If you really want to use json.dumps (python built-in), then you have to do a little bit of extra
import json
from pydantic.json import pydantic_encoder
obs = Observation(**json_data)
obs = obs.dict()
print(json.dumps(obs,indent=2, default=pydantic_encoder))
Thanks for the clarification! I hadn't figured out that I needed the pydantic_encoder.
Description
Creation of resource objects fails for some data types when parsing and creating resource objects from json data. This is the case for decimal within e.g. Quantity and for datetime. Calling .dict() on the object does not return a valid python dict.
What I Did