Apache Avro Schema Types

Avro primitive, complex and logical types with JSON schema representation.

Searchable Apache Avro type reference covering the eight primitives, complex types (record, enum, array, map, union, fixed) and logical types like decimal, date and timestamp-millis with JSON schema syntax. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What are the primitive types in Avro?

Avro defines eight primitives: null, boolean, int (32-bit), long (64-bit), float, double, bytes and string. int and long are variable-length zig-zag encoded, and bytes/string are length-prefixed.

Apache Avro schema types

Apache Avro is a compact, schema-driven binary serialization format used heavily in Kafka topics and the Hadoop ecosystem. Unlike Protobuf, a schema is itself valid JSON, which makes it easy to store in a Schema Registry and evolve without recompiling code. This reference lists every type — primitives, complex types, and logical types — with the JSON shape needed in a .avsc file.

Three families of Avro types

1. Primitive types

Avro defines eight primitives, specified as a bare JSON string:

TypeJSONNotes
null"null"The absence of a value
boolean"boolean"true or false
int"int"32-bit signed integer, ZigZag-encoded
long"long"64-bit signed integer, ZigZag-encoded
float"float"Single-precision IEEE 754
double"double"Double-precision IEEE 754
bytes"bytes"Sequence of 8-bit unsigned bytes
string"string"Unicode character sequence (UTF-8)

int and long use variable-length ZigZag encoding, so small absolute values (positive or negative) occupy very few bytes — one byte for values in −64 to 63.

2. Complex types

Complex types are JSON objects with a "type" field:

  • record — a named object with a list of fields, each carrying a name and a nested schema.
  • enum — a named type whose value is one of a fixed set of symbols strings.
  • array — a list of items all of the same schema.
  • map — string keys mapping to values all of the same schema.
  • union — a value that is exactly one of several listed schemas, written as a JSON array: ["null", "string"].
  • fixed — exactly size bytes, identified by name.

3. Logical types

Logical types annotate a primitive or complex base type with semantic meaning using a logicalType attribute. Readers that do not recognise the logical type silently fall back to the base type — forward compatibility is guaranteed.

Logical typeBase typeMeaning
decimalbytes or fixedArbitrary-precision decimal, with precision and scale
dateintDays since Unix epoch (1970-01-01)
time-millisintMilliseconds since midnight UTC
time-microslongMicroseconds since midnight UTC
timestamp-millislongMilliseconds since Unix epoch
timestamp-microslongMicroseconds since Unix epoch
durationfixed(12)Months, days, milliseconds (unsigned)
uuidstringRFC 4122 UUID string

Schema evolution rules

Avro’s power comes from schema evolution: readers and writers can use different schema versions as long as the change is backward or forward compatible. Safe changes include:

  • Adding a field with a default value.
  • Removing a field that had a default value.
  • Changing int to long (widening is safe).

Unsafe changes include renaming a field without an alias, removing a field without a default, and narrowing types.

Practical example

A nullable timestamp field inside a record:

{
  "type": "record",
  "name": "Event",
  "namespace": "com.example",
  "fields": [
    { "name": "id", "type": "string" },
    {
      "name": "createdAt",
      "type": ["null", { "type": "long", "logicalType": "timestamp-millis" }],
      "default": null
    }
  ]
}

Key conventions: put "null" first in a union when the default is null — Avro requires the default value to match the first type in the union. Always set "default": null so existing data without the field can be read by a schema that adds it later. Use the filter below to find the exact JSON shape for any Avro type.