DevTools Logo

Avro Schema to TypeScript

Avro Schema to TypeScript

Convert Apache Avro schemas into deterministic TypeScript and JSON Schema locally

Avro JSON input

Paste an Avro schema JSON document and generate deterministic TypeScript interfaces or JSON Schema. Primitive mappings, nullable unions, defaults, enums, fixed values, and logical type notes are supported locally.

    Examples

    Nullable field plus enum

    Input
    compileAvroSchema({ type: "record", name: "User", fields: [{ name: "nickname", type: ["null", "string"] }, { name: "status", type: { type: "enum", name: "Status", symbols: ["NEW", "OLD"] } }] })
    Output
    { typescript: "nickname: string | undefined; ... export type Status = \"NEW\" | \"OLD\";" }

    Null unions sort undefined last and enums become literal type aliases.

    Logical type annotation

    Input
    compileAvroSchema({ type: "record", name: "E", fields: [{ name: "when", type: { type: "long", logicalType: "timestamp-millis" } }] })
    Output
    { typescript contains "when: number; // logicalType: timestamp-millis" }

    Wrapped primitive logical types surface as field comments plus JSON Schema descriptions.

    About this tool

    Avro Schema to TypeScript compiles schemas with compileAvroSchema(schema) and compileAvroJson(raw) (aliases avroSchemaToTypeScript/avroToTypeScript, avroSchemaToJsonSchema/avroToJsonSchema): primitives map null → undefined, boolean → boolean, int/long/float/double → number, bytes → Uint8Array, and string → string, while unions join deduplicated branches with undefined sorted last, so ["null", "string"] and ["string", "null"] both emit string | undefined.

    Named types emit declarations: record becomes an interface with doc/default comments per field, enum becomes a string-literal union type alias, fixed becomes Uint8Array with a size comment, and logicalType appends a /* logicalType: x */ note (surfaced as a field comment for wrapped primitives). The root declaration leads and remaining declarations sort alphabetically, making repeated compiles byte-identical.

    JSON Schema output targets draft 2020-12 with sorted $defs: bytes map to base64 strings, numeric Avro types to number, records to object properties with every field required (defaults preserved), enums to string enums, and logicalType to a description. Invalid JSON throws Avro schema is not valid JSON, empty unions and missing fields/items/values/symbols/size throw descriptive errors.

    How to use this tool

    1. Paste the schema

      Provide an Avro JSON object, type string, or union array — or raw JSON text to compileAvroJson.

    2. Read the types

      Copy the root-first TypeScript: interfaces for records, literal unions for enums, Uint8Array for bytes/fixed.

    3. Validate with JSON Schema

      Use the $defs output for runtime validation alongside the static types.

    4. Check errors

      Malformed JSON, empty unions, and records without fields report explicit messages.

    Use cases

    Typing event pipelines

    Generate client interfaces from registry Avro schemas for Kafka or Pulsar topics.

    Bridging static and runtime checks

    Ship TypeScript types for editors plus JSON Schema for payload validation.

    Documenting nullable contracts

    Make optional semantics explicit with T | undefined instead of silent nulls.

    Common mistakes

    Mistake:Expecting null to stay null in TypeScript.

    Fix:Avro null maps to undefined by design — nullable unions read string | undefined.

    Mistake:Assuming declaration order follows field order.

    Fix:Non-root declarations sort alphabetically, so Apple precedes Zebra regardless of field position.

    Frequently asked questions

    What does this tool do?

    It compiles Avro schemas with compileAvroSchema (or raw JSON with compileAvroJson) into TypeScript declarations plus draft 2020-12 JSON Schema with sorted $defs — records to interfaces, enums to literal unions, bytes/fixed to Uint8Array.

    How are nullables, logical types, and ordering handled?

    Null maps to undefined with unions emitting T | undefined (undefined last regardless of input order); logicalType appends a note and field comment plus a JSON Schema description; the root leads and remaining declarations sort alphabetically with byte-identical repeats.

    Is my schema uploaded or stored?

    No. Parsing, type mapping, and schema emission run entirely in your browser.

    Why did compilation throw, or null become undefined?

    Invalid JSON throws Avro schema is not valid JSON while empty unions and records without fields throw descriptive errors; null → undefined is by design, so nullable fields read string | undefined.

    References & standards

    .env Secret Safety Linter

    Validate .env syntax and spot likely leaked credentials or placeholder secrets.

    .htaccess Generator

    Build an Apache .htaccess — HTTPS redirects, rewrites, error pages, security headers, and basic auth

    2D Fluid Dynamics & Particle Physics Sandbox

    A physics playground with two engines sharing one canvas. The fluid mode runs a real Eulerian Navier-Stokes solver — semi-Lagrangian advection, explicit diffusion, Jacobi pressure projection and vorticity confinement — that you paint with dye and velocity using mouse or touch. The particle mode is a damped Verlet N-body engine with gravity wells, Coulomb attractors and repulsors, spring links, wall restitution and elastic circle collisions. Particle counts adapt to the device (100k target on WebGL2 desktop, 2k-5k on CPU fallback), and every configuration exports as runnable code: a Matter.js world, a PixiJS ticker setup, or a standalone vanilla Canvas engine.

    AI Function Calling Schema Generator

    Generate function calling JSON schemas from TypeScript interfaces

    Algorithm Arena & Data Structure Visualizer

    Interactive arena for algorithms and data structures: eight sorting algorithms racing on one seeded input, six pathfinding algorithms walking generated mazes, and BST, AVL, Red-Black, B-tree, heap and trie operations replayed step by step with rotations highlighted. Every run shows the Big-O table and the phase-highlighted reference implementation in four languages, and compared values can be played as pitch (sonification) through the shared audio engine. Everything runs client-side; inputs never leave the browser.

    Ansible Playbook Generator

    Build an Ansible playbook — hosts, vars, and tasks with modules — as YAML