How to model and marshal JSON list object with flask-restx marshalling

838 Views Asked by At

I have a Flask REST API that expects a list of dictionary values (represents a batch) in the POST request, which is valid JSON, and I would like to define the resource fields with flask-restx, but am uncertain how to go about it, as there is no key for the list (The structure is not {'id':[{},...{}]}, but really plainly [{},...,{}]).

As a minimal example, I tried to do something like this, which fails:

from flask_restx import marshal, fields
resource_fields = [{"A":fields.String, "B":fields.Integer, "C": fields.Float}]
data=[{"A":"Q", "B":1, "C": 3.0},{"A":"K", "B":2, "C": 4.0}]
marshal(resource_fields, data) # this fails

Unfortunately, for the moment, I need to implement this using the flask libraries, marshmallow is not an option at this point in time.

Any help is appreciated - thanks!

0

There are 0 best solutions below