Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 370
Julmust Avatar asked Feb 01 '26 22:02

Julmust


1 Answers

Avro requires a nested type for declaring an array:

{
  "type": "record",
  "name": "Avro",
  "fields": [
    ...
    {
      "name": "Tags",
      "type": {
        "type": "array",
        "items": "string",
        "default": []
      }
    }
    ...
  ]
}
like image 141
Kamal Aboul-Hosn Avatar answered Feb 04 '26 02:02

Kamal Aboul-Hosn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!