Is it possible to define marshmallow schema for top-level lists (e.g. obj = ['John', 'Bill', 'Jack']
) or dictionaries (e.g. obj = {'user1': 123, 'user2': 456, 'user3': 789}
- keys are arbitrary)?
Top-level dict is the normal case. To accept arbitrary keys, see unknown=INCLUDE, but then you have no validation, unlike when using the Dict
field.
A solution to this would be either to define a default Field for unknown fields, or to extend Field to let it act as Schema. The former was already suggested (by me, I belive) and shouldn't be too hard to achieve but no one has taken the time to work on it. The latter was suggested by Jared and would be an important refactor. No one is working on it.
Top-level list of dicts is the normal case of using a schema with many=True. Top-level list of anything is not achievable yet. This would work with the refactor mentioned above.