【发布时间】:2017-11-10 01:52:06
【问题描述】:
我想要一个带有以下输出 json 的棉花糖 Schema -
{
"_id": "aae216334c3611e78a3e06148752fd79",
"_time": 20.79606056213379,
"more_data" : {...}
}
Marshmallow 不会序列化私有成员,所以这是我能得到的最接近的 -
class ApiSchema(Schema):
class Meta:
strict = True
time = fields.Number()
id = fields.String()
但我确实需要输出 json 中的下划线。
有没有办法告诉 Marshmallow 使用不同的名称对字段进行序列化?
【问题讨论】:
标签: python json python-2.7 marshmallow