Avro Schema Validator
Validate an Apache Avro schema, test a JSON record against it, infer a schema from sample JSON and generate data that passes. Runs in your browser.
The interactive tool loads here when JavaScript runs.
About this toolWhat is the Avro Schema Validator?
The Avro Schema Validator checks an Apache Avro schema against the rules of the specification and tests JSON records against it. It walks the whole schema: records, enums, arrays, maps, fixed types, unions, named type references and field defaults, and lists every problem it finds with a path such as $.fields[2].type.
Record checks follow Avro's type rules, including the 32-bit range of int, enum symbols and nested records. Records are given as plain JSON, so a nullable field is written as "age": 30, not the {"int": 30} wrapper used by Avro's own JSON encoding. You can also upload a JSON file of sample data to infer a starting schema, and generate a sample record that passes the schema.
It works on JSON only. Binary .avro container files cannot be opened here, and the tool does not check reader and writer schema compatibility for schema evolution.
- Full recursive schema check: records, enums, arrays, maps, fixed and unions
- Named type references, namespaces and recursive records
- Union default and duplicate-field checks
- Record validation with 32-bit int range and enum symbols
- Schema inference from JSON and sample record generation
Updated
How to use the Avro Schema Validator
- Click Load Sample Schema & Data to see a working example, or paste your schema into the Schema (JSON) box.
- Click Validate Schema. The result lists the name, namespace and each field with its type, or every error with its location.
- Paste a JSON record into the Data (JSON) box and click Validate Data to check it against the schema.
- Click Generate Sample to create a record that satisfies the schema, useful as a test fixture.
- To start from existing data, use Upload Avro File with a .json data file, review the Inferred Schema and click Use as Schema.
Worked examples
A union default in the wrong order
Input
{"type": "record", "name": "User", "fields": [{"name": "age", "type": ["int", "null"], "default": null}]}Output
$.fields[0]: default null does not match the first union branch
Avro checks a union default against its first branch only. Swap the branches to ["null", "int"] and the schema becomes valid.
A record with a wrong type
Input
Sample schema, data with "age": "thirty" and no "active" field
Output
Errors: age: "thirty" does not match any branch of union [null, int] Warnings: active not provided, the reader will use the default true
A missing field with a default is only a warning, because Avro readers fill it in. A string in a null-or-int union is an error.
Background and insight
Avro was created by Doug Cutting, the author of Hadoop and Lucene, and became an Apache project in 2009. Its schemas are JSON documents, and its binary encoding contains no field names or tags at all: values are written in schema order, so a reader must have the writer's schema to decode anything. That is why Avro files embed the schema in their header and why Kafka deployments pair Avro with a schema registry.
Avro's real strength is schema resolution. A reader can use a newer schema than the writer as long as fields added in the reader schema have defaults; fields the reader schema dropped are simply ignored. This is also where most mistakes happen. A default for a union must match the first branch, so ["null", "string"] takes default null but ["string", "null"] needs a string default. This validator checks that rule, which many hand-written schemas break.
Names matter more than people expect. Record, enum and fixed names must match [A-Za-z_][A-Za-z0-9_]*, enum symbols follow the same rule, and a namespace plus a name forms the full name used to refer back to a type. A record can reference itself by name, which is how linked lists and trees are modelled.
Common use cases
Reviewing schema changes
Validate a new version of a Kafka topic schema before registering it, catching duplicate fields and bad defaults early.
Debugging rejected records
Paste a record a producer refused to serialize and find the exact field and type that failed.
Bootstrapping a schema
Infer a first schema from a sample JSON event, then tighten types such as long to int and add docs and defaults.
Creating fixtures
Generate a valid sample record to seed unit tests for a consumer.
Tips and limitations
- Put "null" first in nullable unions and give the field "default": null. That is the pattern schema evolution needs.
- Inferred schemas map every integer to long and every null to ["null", "string"]. Review them before use.
- Records here are plain JSON. If your data uses Avro JSON encoding with {"string": "x"} wrappers, unwrap the union values first.
- Extra fields in a record produce a warning, not an error, because Avro writers simply ignore them.
- bytes and fixed values are checked as strings; fixed values must have exactly size characters.
Sources and further reading
- Apache Avro Specification, Apache Software Foundation. Schema rules, names, union defaults, binary encoding and schema resolution
- Schema Registry for Confluent Platform, Confluent. How Kafka deployments pair Avro with a schema registry
Frequently asked questions
How do I validate an Avro schema online?
Paste the schema JSON into the Schema box and click Validate Schema. The checker walks every nested type and reports each problem with a JSON path, such as an unknown type name, a duplicate field, an enum symbol that is not a valid name, or a default that does not match its type.
Why is my Avro union default rejected?
Avro requires a union field's default to match the first type in the union. A field typed ["string", "null"] with default null is invalid. Reorder it to ["null", "string"], which is the usual way to declare an optional field.
Can I validate a binary .avro file here?
No. The tool reads JSON schemas and JSON records only. To inspect a binary Avro container file, use avro-tools tojson from the Apache Avro Java distribution or the fastavro Python package, then paste a record here.
What is the difference between Avro int and long?
int is a signed 32-bit integer (-2,147,483,648 to 2,147,483,647) and long is a signed 64-bit integer. Both are written as variable-length zig-zag numbers, so small values take one byte either way. This validator flags ints outside the 32-bit range.
Does this check schema compatibility between versions?
No. It validates one schema and records against it. Backward and forward compatibility checks compare a reader schema with a writer schema, which is what a schema registry such as Confluent's does when you register a new version.
Why does a nullable field need {"int": 30} in some tools?
Avro's official JSON encoding wraps union values in an object naming the branch, so the decoder knows which type was meant. This tool accepts the plain value instead, 30 or null, which is how most application JSON looks.
Is there an in-depth guide to the Avro Schema Validator?
Yes. “Avro vs Protobuf: Schemas, Encoding and Safe Evolution” covers the background, how it works, common pitfalls and worked examples. Read the full guide.
Related Tools You May Like
Free, in-browser tools that pair well with this one.