pydantic- json键没有有效的python字段名称
我有一个带有键的JSON,其中包含python字段名称无法包含的字符:
{
"mlflow.source.git.commit": "fbe812fe",
"other.key": "other.value"
}
如何使用pydantic
来解析这样的JSON?我想给它一个别名和实际关键名称,例如
class Tags(pydantic.BaseModel):
commit = field(key="mlflow.source.git.commit", type=str)
I have a json with keys containing characters that a python field name can't contain:
{
"mlflow.source.git.commit": "fbe812fe",
"other.key": "other.value"
}
How to use pydantic
to parse such a json? I'd like to give it an alias and actual key name, like
class Tags(pydantic.BaseModel):
commit = field(key="mlflow.source.git.commit", type=str)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是可以使用
pydantic.field(alias =“ ...”)
:This is possible using
pydantic.Field(alias="...")
: