简体   繁体   中英

Renaming Fastapi/Pydantic json output fields

As CamelCase is more idiomatic in json but underscores are more idiomatic in databases i wonder how to map someting like article_id (in database and hence the model) to articleId as the json output of fastapi/pydantic? Is there an easy way?

You can use alias generator from Pydantic. Here is a good article for it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM