Can you put comments in Avro JSON schema files?

jfritz42 picture jfritz42 · May 23, 2013 · Viewed 7.6k times · Source

I'm writing my first Avro schema, which uses JSON as the schema language. I know you cannot put comments into plain JSON, but I'm wondering if the Avro tool allows comments. E.g. Perhaps it strips them (like a preprocessor) before parsing the JSON.

Edit: I'm using the C++ Avro toolchain

Answer

John Dough picture John Dough · Nov 16, 2016

Yes, but it is limited. In the schema, Avro data types 'record', 'enum', and 'fixed' allow for a 'doc' field that contains an arbitrary documentation string. For example:

{"type": "record", "name": "test.Weather",
 "doc": "A weather reading.",
 "fields": [
     {"name": "station", "type": "string", "order": "ignore"},
     {"name": "time", "type": "long"},
     {"name": "temp", "type": "int"}
 ]
}

From the official Avro spec:

doc: a JSON string providing documentation to the user of this schema (optional).

https://avro.apache.org/docs/current/spec.html#schema_record

An example: https://github.com/apache/avro/blob/33d495840c896b693b7f37b5ec786ac1acacd3b4/share/test/schemas/weather.avsc#L2