'Pydantic - Find key in JSON File to use for object creation
Is there any way to write a custom json fileparser for a pydantic class? I have json files that have multiple objects configured in them and want to use the value of the objectname for the creation of the object.
// config.json
{
"object_type_1": {
"name" : "test1",
"value" : "mock",
},
"totally_different_object" : {
"color" : "blue",
"something" : "else",
}
I would like to write someting like
from pydantic import BaseModel
class ObjectType1(BaseModel):
name : str
value : str
object_typ_1_example = ObjectType1.parse_file("config.json", object_key = "object_type_1")
But I couldn't find any example
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
