Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create raw list Schema #2212

Open
l00p1n6 opened this issue Nov 29, 2023 · 1 comment
Open

Create raw list Schema #2212

l00p1n6 opened this issue Nov 29, 2023 · 1 comment
Labels

Comments

@l00p1n6
Copy link

l00p1n6 commented Nov 29, 2023

How can one create Schema derived class from a list only data?

For input with a field value, i.e. dictionary, e.g.:

{
  "string_list": [
    "one",
    "two",
    "three"
  ]
}

one can use;

class StringListSchema(Schema):
    string_list = fields.List(fields.Str())

But how can one so it when input is just a list:

[
  "one",
  "two",
  "three"
]

?

NB: both are valid JSONs

@lafrech
Copy link
Member

lafrech commented Jan 18, 2024

I don't think you can do that with marshmallow. I'm pretty sure there was once a discussion about it, maybe involving sort of merging Schema and Field. I can't find it.

You could probably use a pre_load to wrap the payload into a dict with a single key and using that key as name for the List field in the schema, but this sucks, of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants