Avro Formatter
Format, validate, and prettify Apache Avro schemas online. Syntax highlighting, minification, tree view, and Avro-specific type validation.
About
Apache Avro schemas define the structure of serialized data using a JSON-based format. A malformed schema - a missing type field, an undeclared named type in a union, or an invalid logical type annotation - will cause serialization failures at runtime, corrupting data pipelines and blocking downstream consumers. This tool parses Avro schema JSON, validates it against the Avro 1.11 specification (primitives: null, boolean, int, long, float, double, bytes, string; complex: record, enum, array, map, fixed, unions), and reports type-level errors with precise locations.
The formatter applies configurable indentation (2 or 4 spaces, or tabs), produces syntax-highlighted output with Avro-aware keyword coloring, and supports minification for compact storage. It approximates validation of logical types (date, timestamp-millis, decimal, uuid) but does not perform full schema resolution across multiple files. For multi-file schema registries, validate each file independently and verify cross-references manually.
Formulas
Avro schema validation follows a recursive type-resolution algorithm. For each node in the JSON structure, the validator determines the type category and checks required attributes.
validate(node) →
Where validateRecord(node) checks: node.name must exist and match the pattern [A-Za-z_][A-Za-z0-9_]*. node.fields must be a non-empty array. Each field must have name and type, where type is recursively validated. validateEnum(node) checks that symbols is a non-empty array of unique strings. validateUnion(node) verifies no duplicate types and no nested unions (unions within unions are forbidden by the Avro spec).
The name validation regex: pattern = /^[A-Za-z_][A-Za-z0-9_]*$/. Namespace validation: nsPattern = /^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$/.
Reference Data
| Type Category | Type Name | JSON Representation | Description | Example |
|---|---|---|---|---|
| Primitive | null | "null" | No value | "null" |
| Primitive | boolean | "boolean" | Binary value | "boolean" |
| Primitive | int | "int" | 32-bit signed integer | "int" |
| Primitive | long | "long" | 64-bit signed integer | "long" |
| Primitive | float | "float" | 32-bit IEEE 754 float | "float" |
| Primitive | double | "double" | 64-bit IEEE 754 float | "double" |
| Primitive | bytes | "bytes" | Sequence of 8-bit unsigned bytes | "bytes" |
| Primitive | string | "string" | Unicode character sequence | "string" |
| Complex | record | {"type":"record",...} | Named record with fields | Requires name, fields |
| Complex | enum | {"type":"enum",...} | Enumeration of symbols | Requires name, symbols |
| Complex | array | {"type":"array",...} | Ordered collection | Requires items |
| Complex | map | {"type":"map",...} | String-keyed dictionary | Requires values |
| Complex | fixed | {"type":"fixed",...} | Fixed-size byte sequence | Requires name, size |
| Complex | Union | ["null","string"] | One of several types | JSON array of types |
| Logical | date | "logicalType":"date" | Days since epoch (int) | Base type must be int |
| Logical | time-millis | "logicalType":"time-millis" | Milliseconds since midnight (int) | Base type must be int |
| Logical | time-micros | "logicalType":"time-micros" | Microseconds since midnight (long) | Base type must be long |
| Logical | timestamp-millis | "logicalType":"timestamp-millis" | Milliseconds since epoch (long) | Base type must be long |
| Logical | timestamp-micros | "logicalType":"timestamp-micros" | Microseconds since epoch (long) | Base type must be long |
| Logical | decimal | "logicalType":"decimal" | Arbitrary-precision decimal | Base: bytes or fixed; requires precision, scale |
| Logical | uuid | "logicalType":"uuid" | RFC 4122 UUID | Base type must be string |
| Logical | duration | "logicalType":"duration" | 12-byte fixed duration | Base: fixed with size = 12 |
| Field Attr | name | String | Field/type identifier | Must match [A-Za-z_][A-Za-z0-9_]* |
| Field Attr | doc | String | Documentation string | Optional on records, fields, enums |
| Field Attr | default | Any | Default value for field | Must match field type; union default matches first type |
| Field Attr | order | String | Sort order | "ascending", "descending", "ignore" |
| Field Attr | aliases | Array | Alternative names | Array of strings |
| Schema Attr | namespace | String | Dot-separated namespace | "com.example.avro" |