0

using marshmallow how can I build and schema that accepts list of string, boolean and numbers

Something like this?

meta = fields.List(fields.Str() or fields.Bool())

example data

[ "a", "b", true, 1, false]
Rolly
  • 3,205
  • 3
  • 26
  • 35
  • 1
    Does this answer your question? [Python Marshmallow Field can be two different types](https://stackoverflow.com/questions/61614546/python-marshmallow-field-can-be-two-different-types) Also there are packages in the [marshmallow ecosystem](https://github.com/marshmallow-code/marshmallow/wiki/Ecosystem) that may help with this, e.g. `python-marshmallow-union`. The `marshmallow` core maintainers said [they do not intend to include a union-type field](https://github.com/marshmallow-code/marshmallow/issues/1191) anytime soon. – Daniil Fajnberg May 24 '23 at 14:36

0 Answers0