An Avro schema specifies the structure of an Avro data block. It specifies what data fields are expected and how the values are represented. Information about Avro schema and its specification is available here.
Note the following points about Avro schemas:
•An Avro schema is created in JSON format
•An Avro schema can be: a JSON string, a JSON object, or a JSON array
•An Avro schema can contain four attributes: name, namespace, type, and fields
•There are eight primitive data types: null, boolean, int, long, float, double, bytes, and string
•There are six complex types: records, enums, arrays, maps, unions, and fixed
•Primitive types have no attributes; each complex type has its own set of attributes
For details and more information about Avro schema, see the Avro schema specification.
Given below are simple examples of Avro schemas, each with corresponding Avro data snippets in JSON format. Note that the schema defines a certain structure. In some cases, when the defined structure is instantiated multiple times, the resulting output might not be valid JSON. For example, a schema might define the structure of a JSON object. If the JSON object is instantiated multiple times, each object (separately) could be valid against the Avro schema, but the entire document would not be valid JSON—because there is no container object. If valid JSON is required, you might want to rewrite the Avro schema to validate an array of JSON objects. Compare Examples 4 and 5 below to see this point illustrated.
If you wish to use XMLSpy's features for Avro-related editing and validating, then XMLSpy must be able to recognize a file as an Avro schema. A file is recognized as an Avro schema if the file's extension is defined as such in XMLSpy's Options dialog (Tools | Options | File types). XMLSpy's default settings define one file extension—the .avsc extension—as being that of an Avro schema file. If you wish to create other file extensions that specify Avro schema documents, add these file extensions as Avro schema extensions to the list in the Options dialog.
In XMLSpy, you can create a new file as an Avro schema by specifying an Avro schema file extension as its file type. XMLSpy provides intelligent editing help as you type. This includes context-sensitive keyword suggestions, automatic entry of bracket-, brace-, and quote-pairs, syntax coloring, and auto-completion of keywords. Additionally, there are three entry helpers: JSON Properties, JSON Values, and JSON Entities. The entries that are available in them are context-sensitive. Double-click an entry to insert it at the current cursor location. You can then validate the file against the Avro schema specification with the Validate | Validate XML (F8) menu command.