Home > Enterprise >  Converting json to Avro with inconsistently ordered fields in json
Converting json to Avro with inconsistently ordered fields in json

Time:03-02

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?

CodePudding user response:

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.

  • Related