JSON to Avro Schema
Infer an Avro record schema from a JSON object: field names in document order, integers as long, decimals as double, arrays from their first item.
What the JSON to Avro Schema does
The inference is direct: string, boolean, long for an integer, double for anything fractional, and null for null. An array's type comes from its first item, and an object becomes a record named after its field.
A JSON root that is an array or a scalar is refused, because the schema this page emits describes one record and the root is its name.
Inference sees one sample: a field that happens to be null, or an array with one element, is typed as narrowly as that value. A field that can be absent is not made a union with null, because the sample cannot show absence.
How to use it
Paste the object into the JSON object box, or press Run with the example already there.
Read the Avro schema below: the root record is named Root and its fields follow the JSON key order.
Check an Avro schema numeric field — an integer is long and a fractional value is double.
Worked example
Input:
{"id":1,"name":"Ada"}
Output:
{
"type": "record",
"name": "Root",
"fields": [
{
"name": "id",
"type": "long"
},
{
"name": "name",
"type": "string"
}
]
}
Why it runs in your browser
The result is produced on this page with JavaScript, so it works offline after the page loads and nothing you enter is sent anywhere.
An Avro record schema inferred from a JSON sample: one field per key, in the order the document lists them, with the narrowest type the value supports.
An integer becomes `long`, a fractional number `double`, an array a typed array, and a nested object a nested record.
What it does, and what it does not
The inference is direct: string, boolean, long for an integer, double for anything fractional, and null for null. An array's type comes from its first item, and an object becomes a record named after its field.
A JSON root that is an array or a scalar is refused, because the schema this page emits describes one record and the root is its name.
Inference sees one sample: a field that happens to be null, or an array with one element, is typed as narrowly as that value. A field that can be absent is not made a union with null, because the sample cannot show absence.
How to use JSON to Avro Schema
Paste the object into the JSON object box, or press Run with the example already there.
Read the Avro schema below: the root record is named Root and its fields follow the JSON key order.
Check an Avro schema numeric field — an integer is `long` and a fractional value is `double`.
What to Expect
Best for
- Starting an Avro schema from a real message
- Checking the type a JSON value maps to
Not ideal for
- A schema with optional fields, which needs a union by hand
- A sample that does not represent every value
What this tool keeps
- JSON key order as field order
- An array's element type from its first item
What may need cleanup
- Make a nullable field a null-plus-type union by hand
- Widen a long to int where you know the range
Common errors
- The page refuses it: the JSON root must be an object
Example use cases
- Drafting a schema from a captured message
- Checking a producer's payload shape
Sample input
JSON object: {"id":1,"name":"Ada"}
Sample output
Avro schema: { …
Who this is for
- Data engineers building a schema registry
- Developers consuming an Avro topic
Frequently asked questions
Why is every integer a long?
JSON has one number type, and long is the safe Avro type for a whole number. Narrow it to int where you know the range.
Why is the root refused when it is an array?
The page emits one record, and a record has a name. An array at the root has no field name to take a name from, so it is refused rather than invented.
What about a null field?
It becomes the null type. A field that is sometimes null needs a ["null", "string"] union written by hand, because one sample cannot show both.
Build custom tools for your store
Join the SDK program to create useful ecommerce utilities for your store.