JSON to Avro Schema Generator

Generate Apache Avro schema definitions from JSON data for Kafka, Hadoop, and Spark pipelines.

What is JSON to Avro Schema Generator?

Apache Avro is a compact binary serialization system that separates schema from data, making serialized records 3–10× smaller than equivalent JSON because field names are stored once in the schema rather than repeated in every message. Avro schemas are JSON documents themselves, describing records with typed fields, and are the default serialization format for Apache Kafka, Hadoop MapReduce, and Spark Structured Streaming. This generator inspects your JSON sample, infers the correct Avro primitive type for each value (`string`, `int`, `long`, `double`, `boolean`), wraps null fields in a union type `["null", "type"]` with a default of null, converts arrays into `{type: "array", items: ...}` constructs, and promotes nested objects into inline record definitions. The output is a valid `.avsc` file you can register directly with the Confluent Schema Registry or use with Kafka producers and consumers.

How to Use

  1. Set the record name (e.g. OrderEvent) and a reverse-DNS namespace (e.g. com.example.orders) to follow Avro naming conventions
  2. Paste a representative JSON message from your Kafka topic or data pipeline into the input area
  3. Click "Generate Avro Schema" to produce a complete .avsc definition with proper type mappings and nullable unions
  4. Register the schema with your Schema Registry, then reference it by subject name in your Kafka producer/consumer configuration
  5. Validate the schema using avro-tools jar or the Confluent Schema Registry API before deploying to production

Why Use This Tool?

Produces schema files compatible with Confluent Schema Registry, Kafka Connect SMTs, and Avro-based SerDe classes out of the box
Null values automatically generate Avro union types ["null", "type"] with default: null, preventing deserialization failures on missing fields
Integer values exceeding the int32 range are automatically promoted to long, avoiding silent overflow
Nested objects become inline record definitions, keeping the schema self-contained in a single .avsc file without external type references
The generated schema can be used with Kafka Streams, Spark Structured Streaming, and Flink Avro formats without modification

Tips & Best Practices

  • Always provide a namespace (e.g. com.company.domain) — without it, Avro places the record in the default package, which causes naming collisions in multi-topic environments
  • Kafka consumers using the Confluent SerDe expect the schema to be registered before messages arrive. Register the schema first, then start your producer
  • If your JSON contains decimal prices or monetary values, manually change the inferred double type to bytes with logicalType: "decimal" after generation for precise financial calculations
  • Avro union types must list "null" first when the default is null — the generator handles this ordering automatically, but be aware if you edit the schema manually
  • Use avro-tools tojson and fromjson commands to verify that your data serializes and deserializes correctly against the generated schema before deploying to Kafka

Frequently Asked Questions

How does JSON map to Avro primitive types?

JSON strings map to string, integers within the int32 range map to int, integers exceeding int32 map to long, floating-point numbers map to double, booleans map to boolean, null values produce a union ["null", "string"] with default null, arrays become {type: "array", items: ...}, and nested objects become inline record definitions with their own fields array.

When should I avoid using this generator?

Skip this tool if your data uses Avro logical types (decimal, date, timestamp-millis, uuid) — the generator infers only primitive types from JSON values and cannot detect logical types. Also avoid it if your schema requires documentation strings, aliases, or custom order attributes that cannot be inferred from a data sample alone.

Can I use this schema with Confluent Schema Registry?

Yes. The output is a valid Avro schema JSON document. Register it via the Schema Registry REST API: curl -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" --data '{"schema": "..."}' http://localhost:8081/subjects/your-topic-value/versions. The schema ID will be prepended to every serialized message automatically.

Why does null generate a union type instead of a simple null type?

Avro fields must have a non-null default when used in a union. The pattern ["null", "type"] with default: null means the field can be either null or the specified type, and defaults to null when absent. This is the standard Avro idiom for optional fields and is required by the Kafka Avro serializer.

How do I handle decimal or monetary values?

The generator maps all floating-point numbers to double. For financial precision, manually replace the type with {"type": "bytes", "logicalType": "decimal", "precision": 10, "scale": 2} after generation. This avoids floating-point rounding errors in price and balance calculations.

Is my data sent to a server?

No. All schema generation runs entirely in your browser. Your JSON data never leaves your device — there are no network requests, no server-side processing, and no data retention.

Real-world Examples

Kafka order event schema

Generate an Avro schema for an e-commerce order event that will be published to a Kafka topic and consumed by a downstream analytics pipeline.

Input
{
  "orderId": 10042,
  "customerId": "cust-8891",
  "totalAmount": 149.99,
  "items": [
    { "sku": "WH-100", "quantity": 2, "price": 49.99 }
  ],
  "shippedAt": null
}
Output
{
  "type": "record",
  "name": "OrderEvent",
  "namespace": "com.example",
  "fields": [
    {"name": "orderId", "type": "int"},
    {"name": "customerId", "type": "string"},
    {"name": "totalAmount", "type": "double"},
    {"name": "items", "type": {
      "type": "array",
      "items": {
        "type": "record",
        "name": "Item",
        "fields": [
          {"name": "sku", "type": "string"},
          {"name": "quantity", "type": "int"},
          {"name": "price", "type": "double"}
        ]
      }
    }},
    {"name": "shippedAt", "type": ["null", "string"], "default": null}
  ]
}

User activity tracking schema

Create an Avro schema for a user activity event stream captured from a mobile app, with nullable fields for optional tracking data.

Input
{
  "userId": 5001,
  "event": "page_view",
  "timestamp": 1700000000,
  "metadata": null,
  "platform": "ios"
}
Output
{
  "type": "record",
  "name": "UserActivity",
  "namespace": "com.example",
  "fields": [
    {"name": "userId", "type": "int"},
    {"name": "event", "type": "string"},
    {"name": "timestamp", "type": "int"},
    {"name": "metadata", "type": ["null", "string"], "default": null},
    {"name": "platform", "type": "string"}
  ]
}

Related Tools