Format Code Now
/
Format & validateAvro Schema Formatter Next: C Formatter ›

Avro Schema Formatter and Validator

FV-31

Paste an Avro schema to format it, minify it, check it against the Avro rules, or see it as an outline. A broken schema gets an error that names the path to the problem.

Runs in your browser. Nothing is uploaded.

Avro schema (JSON)

Result

How to use it

  1. Paste your Avro schema (the JSON from an .avsc file) into the input box.
  2. Choose Format Avro to pretty print, Minify for one line, Validate to check it, or Outline for a tree.
  3. Pick the indent. Untick the rules check if you only want to pretty print JSON.
  4. Copy the result or download it as an .avsc file.

What gets checked

With the check on, the schema is tested against the Avro rules, not just against JSON syntax. Types must be known: null, boolean, int, long, float, double, bytes, string, or a record, enum, fixed, array or map. Names use letters, digits and underscores. Record fields have unique names, enums have unique symbols, and fixed types have a size. A union cannot hold another union or repeat a type. A named type can be used only after it is defined. A default has to fit the type, and a union default has to fit its first type.

Numbers stay exactly as written

The schema is read with a parser that keeps every number as text, so a default such as 9223372036854775807 is not rounded on the way through. Key order is kept too, so the formatted schema diffs cleanly against the original. The long default check uses exact integer maths, which is how a value just past the 64-bit limit is caught and reported.

The outline view

Outline prints the schema as a tree: the record name, then each field with its type and default, nested records indented under their field. Enums list their symbols, unions list their branches, and arrays and maps say what they hold. A reference to a type defined earlier is shown by name instead of repeating its fields. It is a quick way to read a long schema without scrolling through braces.

Error messages and what to do

MessageWhat it meansFix
Invalid Avro schema at $.fields[0].type: unknown type "strng". It is not a built-in type and no record, enum or fixed with that name is defined before this pointA field uses a type name Avro does not know.Fix the spelling, or define that record, enum or fixed earlier in the schema.
Invalid Avro schema at $.fields[0].default: the default "a" does not fit the type of "x"The default value has the wrong kind of value for the field type.Change the default to match the type, for example a number for int.
Expected ',' or '}' at line 1, column 28The text is not valid JSON at that point.Add the missing comma or closing brace near the position shown.

Questions people ask

How do I format an Avro schema?

Paste the schema into the input box and choose Format Avro. It is pretty printed with 2 spaces, 4 spaces or a tab, with keys in their original order. By default the schema is also checked against the Avro rules, and any problem is reported with its path before anything is printed.

How do I validate an Avro schema online?

Click Validate. A good schema returns a line such as Valid Avro schema: record com.example.User with 6 fields. A bad one returns the path to the first problem, for example $.fields[2].type, and what is wrong there. Fix it and run it again.

What is an .avsc file?

An .avsc file holds an Avro schema written as JSON. It describes the fields and types of a record so that data can be written and read in the compact Avro binary format. The schema is plain JSON, which is why a JSON formatter can read it.

Does it check my data against the schema?

No. It checks the schema itself, not records written with it. It also does not know custom logical types or whether a logicalType fits its base type. To test data you need an Avro library such as the ones for Java, Python or Go.

Can I use it to format plain JSON?

Yes. Untick the check box and the text is pretty printed as ordinary JSON with exact numbers and original key order. Comments and trailing commas are not valid JSON, so they still give a syntax error with a line and column.

Why is a default rejected for a union?

In Avro, a union default must match the first type in the union. A field typed ["null", "string"] can default to null but not to a string. If you want a string default, list string first, or use null as the default.

About this tool

Reads the schema as JSON and keeps every number exactly as written, so a long default such as 9223372036854775807 is not rounded. With the check box on, it also tests the schema against the Avro rules: known types, names with letters, digits and underscores, record fields with unique names, enums with unique symbols, fixed sizes, unions without repeats or nested unions, named types used only after they are defined, and defaults that fit their type (a union default must fit the first type). A failed check names the path to the problem, such as $.fields[2].type. It does not know any custom logical types or check that a logicalType fits its base type, and it cannot test a schema against real data. Untick the box to pretty-print any JSON. Key order is kept and comments are not allowed because JSON has none.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.