litestar-org/polyfactory

Support for Json Type

Closed this issue · 3 comments

Description

class Person(BaseModel):
    names: Json[Any]

person_json = '''
{
     "first_name": "john",
     "last_name": "Doe",
     "nick_name": "lost"
}
'''

p = Person.json_parse(person_json)

This automatically converts the person_json into pydantic Model. But I couldn't find the way to reverse this.

Hi, thanks for the issue. So the JSON is a dict - you mean you want to output the JSON as a string instead of a dict?

Yes. For more info, I am talking about this feature https://pydantic-docs.helpmanual.io/usage/types/#json-type

So, I am not sure what is required here to be honest. Can you show me a code snippet that is failing to do what you need?