Registry / storage / jsonschema-avro

jsonschema-avro

JSON →
library2.1.1jsnpmunverified

Converts JSON Schema definitions into Avro schema definitions. Version 2.1.1 is the latest stable release. This library translates JSON Schema types and structures to Avro, supporting nested objects, arrays, enums, and primitives. It requires input schemas to be fully dereferenced (no external $ref). Lightweight, no runtime dependencies, synchronous conversion. Suitable for generating Avro schemas from existing JSON Schema definitions for use with Avro serialization (e.g., Apache Kafka, Hadoop).

npm install jsonschema-avro
INSTALL
IMPORT
SIG · JSONSCHEMA-AVRO
J
jsonschema-avro
storagejavascriptv2.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

convert
import { convert } from 'jsonschema-avro'
const convert = require('jsonschema-avro').convert
ESM named export available; also works with require via destructuring.
defaultExport
import jsonschemaAvro from 'jsonschema-avro'
Default export is the module itself; use as default import or require.
convert
const jsonschemaAvro = require('jsonschema-avro'); const avro = jsonschemaAvro.convert(jsonSchema)
const convert = require('jsonschema-avro/convert')
CommonJS: require the package and use .convert method.

Demonstrates conversion of a JSON Schema object to an Avro schema using the convert function.

const jsonSchemaAvro = require('jsonschema-avro'); const input = { type: 'object', properties: { firstName: { type: 'string' }, age: { type: 'integer' }, email: { type: 'string', format: 'email' }, address: { type: 'object', properties: { street: { type: 'string' }, city: { type: 'string' } } }, tags: { type: 'array', items: { type: 'string' } } } }; const avro = jsonSchemaAvro.convert(input); console.log(JSON.stringify(avro, null, 2));
Debug
Known issues
gotchaInput JSON schema must be dereferenced (no unresolved $ref). External references are not resolved automatically.
fix
Pre-process the schema with a tool like json-schema-ref-parser to resolve all $ref pointers before passing to convert().
affects: >=0.0.0
gotchaanyOf and allOf combinators are not handled; they will be ignored or cause unexpected output.
fix
Rewrite schemas using anyOf/allOf as union types via enums or other supported patterns, or use a more complete library.
affects: >=0.0.0
gotchaEnum types with mixed types (e.g., ["string", 1]) may produce invalid Avro.
fix
Ensure enum values are all of the same type (Avro enums require strings).
affects: >=0.0.0
breakingPreviously the package may have had different export signatures; older versions may export a function directly instead of an object with .convert method.
fix
Update to v2+ and use require('jsonschema-avro').convert().
affects: <2.0.0
Errors
Common errors & fixes
TypeError: jsonSchemaAvro.convert is not a function
Using an older version (<2.0.0) where the module exports a function directly, or incorrect import/require.
fix
Update to v2+ or use: const convert = require('jsonschema-avro'); convert(input);
Cannot read properties of undefined (reading 'properties')
Input schema contains unresolved $ref pointers, leading to undefined object in nested definitions.
fix
Dereference the schema first using a library like @apidevtools/json-schema-ref-parser.
Unsupported JSON Schema type: anyOf
The library does not support JSON Schema combinators anyOf/allOf/oneOf.
fix
Restructure the schema to avoid these combinators, or use a different conversion library.
Upgrade
Version history
2.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources
jsonschema-avro — npm install jsonschema-avro · libregistry