[Python] How to build Pydantic models that do not produce nesting on serialization?

Discussão em 'Python' iniciado por Stack, Fevereiro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I am looking for a way to build a model Foo below, where serializing does not produce nesting (and of course Foo still does validation)

    Desired behaviour: bar is validated according to Foo.

    y = Bar(bar=Foo('xxx'))


    Desired output:

    print(y.json())
    # {"bar": "xxx"}

    Continue reading...

Compartilhe esta Página