Input

Output

What does JSON to Avro do?

You have a sample JSON record — say, the body of an API response or one row from a Kafka topic — and you need an Apache Avro schema for it. Writing the .avsc by hand for a 30-field record is tedious. Paste the JSON into the left panel and the right panel hands back a schema with type, name, namespace, and fields already filled in. Drop it into your producer config and start serializing.

The inference walks the JSON value and maps types directly: booleanboolean, integer numbers → long, floats → double, strings → string, objects → nested records, arrays → {type: "array", items: ...}. Field names are lifted as-is, and a default namespace of com.example is applied. The mapping follows the type system in the Avro 1.11 specification — primitives, records, arrays, maps. JSON itself is parsed by RFC 8259 rules via the browser's native JSON.parse().

Inference is a starting point, not a finished design. Look at the output, decide whether <code>orderId</code> should be a <code>string</code> or a logical <code>uuid</code>, whether <code>placedAt</code> should be <code>{"type": "long", "logicalType": "timestamp-millis"}</code>, whether nullable fields should be unions like <code>["null", "string"]</code>. The tool gets you 80% of the way there; the last 20% is where the schema design lives.

How to Use JSON to Avro

Three quick steps. The buttons described below are the actual buttons on this page.

1

Paste, Upload, or Load a Sample

Paste a JSON object or array into the left Input panel. For an array, the first element is used to seed the schema. Click Upload to load a .json file, or hit Sample for a realistic Order array. Quick example of what the input looks like:

{"orderId":"ORD-58231","customerId":"CUST-9012","totalCents":9997,"currency":"USD"}

Both single objects and arrays of records work. The output Avro schema gets named Root with namespace com.example — rename to fit your project (the names matter for Schema Registry subjects).

2

Read the Generated Schema

The right Output panel shows a fully-formed Avro schema. Records nest under fields, arrays declare items, primitives map directly. Look at each field type and decide whether it is what you actually want — the inferrer cannot tell that "2024-04-30" is a date, only that it is a string.

3

Refine, Copy, or Download

Hit Copy to grab the JSON for a Schema Registry POST. Hit Download to save as schema.avsc for your repo. Adjust types, add logicalType annotations, change nullable fields to ["null", "string"] unions, then validate with the Avro Validator before publishing.

When You'd Actually Use This

Bootstrapping a Kafka Producer

You have a JSON event that an upstream service emits, and you need to publish it to a Kafka topic with Avro encoding. Paste the event, get a draft schema, tweak the types, register it. Beats hand-writing 40 fields.

Migrating a JSON API to Avro

You are turning a REST endpoint into an event-driven service. Drop a real response body in here, get the schema scaffolding, then refine the nullable fields and logical types before producing.

Quick Schema Sketches in Code Review

Someone in a PR asks "what would this look like as Avro?" — you paste the JSON sample, take a screenshot of the inferred schema, drop it in the conversation. Faster than firing up a notebook.

Onboarding to a Schema-First Pipeline

New to Avro and trying to understand how a JSON shape maps to records, arrays, and primitives? Run a few JSON samples through this tool and read the output side by side. The mapping clicks fast.

Common Questions

What does it do with nullable fields?

A null in the JSON sample produces the literal Avro type "null" in the schema, which is rarely what you want long-term. To allow null AND a real type, change the inferred type to a union: ["null", "string"] with "default": null. The inferrer cannot guess your intent here — it only sees what is in the sample.

How does it handle arrays of mixed types?

It seeds the array schema from the first element only. If your array has [1, "two", true] the inferred items type will be long, which is wrong. Avro arrays are homogeneous; if your data is genuinely mixed, you need a union as the items type. The tool does not detect that — it is a starting point.

Why are integers becoming long instead of int?

JSON numbers do not carry width information, so picking int would silently overflow on values above 2^31. long is the safe default. If you know your data fits in 32 bits, change "long" to "int" in the output before publishing — Avro int reads slightly faster.

Does it generate logical types like timestamp-millis or decimal?

No. The inferrer maps to physical primitives only. To add logical types, edit the output: change "placedAt": "long" to "placedAt": {"type": "long", "logicalType": "timestamp-millis"}. Same for uuid, date, decimal, and the rest.

Is the JSON sent to a server?

No. Conversion runs entirely in your browser using JSON.parse() and a small inference function. Nothing is uploaded, nothing is logged.

What's the difference between this and JSON Schema?

JSON Schema is a validation language for JSON documents. Avro is a serialization format with its own schema language used for binary encoding and Schema Registry. Both describe data shape, but Avro gives you compact binary records and schema evolution rules out of the box. If you need binary serialization for Kafka or Hadoop, Avro is the answer.

Other Avro and JSON Tools

Inference is one step. These tools handle the rest of the Avro lifecycle: