Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

PubSub Avro schema with JSON array throws Invalid schema definition error

I’m setting up a pub/sub topic to receive some JSON data. One of the fields in the JSON data is an array of strings, like so:

{
    ...
    "Tags": ["2333TAG"],
    ...
}

I’ve tried defining the schema as per the Avro 1.11 spec:

{
  "type": "record",
  "name": "Avro",
  "fields": [
    ...
    {
      "name": "Tags",
      "type": "array",
      "items": "string",
      "default": []
    },
    ...
  ]
}

But when I try to validate the definition, I get the error: Invalid schema definition: Reference node does not refer to previously declared type: array

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any idea of what I might be doing wrong? I have verified that this is the field in the schema that’s throwing the error.

>Solution :

Avro requires a nested type for declaring an array:

{
  "type": "record",
  "name": "Avro",
  "fields": [
    ...
    {
      "name": "Tags",
      "type": {
        "type": "array",
        "items": "string",
        "default": []
      }
    }
    ...
  ]
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading