将 json 转换为 Avro,其中 json 中的字段顺序不一致
假设我有一个 json 对象,其字段如下所示
"segments": [
{
"x": "hello",
"y": "1",
"z": "2"
},
{
"y": "3",
"z": "4",
"x": "world"
}
]
正如您所看到的,该数组包含具有字段 x
、y
、z
的对象但是每个对象都有不同的顺序。假设我的 Avro 架构将顺序定义为 x
、y
、z
。我收到不正确的字段错误,因为第二个元素的顺序错误。除了更改 json 以使两个元素具有正确的顺序之外,还有其他方法可以解决此问题吗?
Say I have a json object with a field that looks like this
"segments": [
{
"x": "hello",
"y": "1",
"z": "2"
},
{
"y": "3",
"z": "4",
"x": "world"
}
]
As you can see the array contains objects with the fields x
, y
, z
however each object has a different ordering. Say my Avro schema defines the ordering to be x
, y
, z
. I get an incorrect field error because the second element has the wrong ordering. Is there any way around this other than changing the json such that both elements have the correct ordering?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JSON 字典是无序的,期望它们按一定顺序可能会导致其他问题。如果您需要元素的顺序不同,则必须自行更改。
JSON dictionaries are unordered and expecting them to be in a certain order is probably going to cause other problems down the road. If you need the elements to be in different orders you will have to change that yourself.