brokenloop/jsontopydantic

Specific json conversion

Opened this issue · 0 comments

The tool currently converts this json

{
  "accounts": {
    "98230": {
      "name": "BHN1",
      "status": "ACTIVE"
    },
    "57150": {
      "name": "Sec",
      "status": "ACTIVE"
    }
  }
}

to something along the lines of

class Accounts(BaseModel):
    field_98230: Field98230 = Field(..., alias='98230')
    field_57150: Field57150 = Field(..., alias='57150')


class Model(BaseModel):
    accounts: Accounts

This might be more useful result rather than having a field for each value

class Model2(BaseModel):
    accounts: Optional[OrderedDict[str, ModelItem]]