Suppose I have following json:
[
{"id":1,"text":"some text","user_id":1},
{"id":1,"text":"some text","user_id":2},
...
]
What would be an appropriate avro schema for this array of objects?
Suppose I have following json:
[
{"id":1,"text":"some text","user_id":1},
{"id":1,"text":"some text","user_id":2},
...
]
What would be an appropriate avro schema for this array of objects?
[short answer]
The appropriate avro schema for this array of objects would look like:
[long answer]
We can use Avro to help us build the above schema by given data object.
Let's use npm package "avsc", which is "Pure JavaScript implementation of the Avro specification".
Since Avro can infer a value's schema we can use following trick to get schema by given data (unfortunately it seems can't show nested schemas, but we can ask twice - for top level structure (array) and then for array element):
Output:
Now let's compose proper schema and try to use it to serialize object and then de-serialize it back!
Output:
We can even enjoy the compact binary representation of the above exercise:
Nice, isn't she?-)