Registry / storage / json-schema-to-avro

json-schema-to-avro

JSON →
library1.1.0jsnpmunverified

Converts JSON Schema definitions into Apache Avro schema format. Version 1.1.0 is the current stable release. The library is lightweight and has minimal dependencies (only tslib). It supports basic JSON Schema types and structures but does not handle advanced features like anyOf or allOf. The input must be fully dereferenced before conversion. It provides a simple API with a single convert function and ships with TypeScript type definitions.

npm install json-schema-to-avro
INSTALL
IMPORT
SIG · JSON-SCHEMA-TO-AVR
J
json-schema-to-avro
storagejavascriptv1.1.0
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.

default (function)
import jsonSchemaAvro from 'json-schema-to-avro'
const { convert } = require('json-schema-to-avro')
Package uses CommonJS; default export is an object with convert method. For ESM, use default import.
convert
import { convert } from 'json-schema-to-avro'
import jsonSchemaAvro from 'json-schema-to-avro'; const { convert } = jsonSchemaAvro;
Named export works with ESM and TypeScript.
types
import type { JsonSchema4, JsonSchema5, AvroSchema } from 'json-schema-to-avro'
TypeScript types are exported for JSON Schema and Avro schema interfaces.

Demonstrates converting a simple JSON Schema object to an Avro schema using the convert function.

import { convert } from 'json-schema-to-avro'; const jsonSchema = { $id: 'http://example.com/schemas/user.json', type: 'object', properties: { name: { type: 'string' }, age: { type: 'integer' }, }, }; const avroSchema = convert(jsonSchema); console.log(JSON.stringify(avroSchema, null, 2));
Debug
Known issues
gotchaInput JSON schema must be fully dereferenced; any unresolved $ref will cause incorrect output or errors.
fix
Use json-schema-ref-parser or similar to resolve external references before calling convert.
affects: *
deprecatedanyOf and allOf are not supported and will be ignored or may cause unexpected results.
fix
Manually transform schemas using anyOf/allOf into supported constructs or consider an alternative library.
affects: *
gotchaThe package does not support JSON Schema drafts beyond draft-04; newer keywords like const or if/then/else are not handled.
fix
Ensure input schema is compliant with draft-04 or earlier.
affects: *
breakingVersion 1.0.0 changed the default export structure; previous versions used a different API.
fix
Update imports to use the convert function as shown in documentation.
affects: 0.x
Errors
Common errors & fixes
TypeError: jsonSchemaAvro.convert is not a function
Incorrect import path or wrong export usage
fix
Use require('json-schema-to-avro').convert or import { convert } from 'json-schema-to-avro'.
Error: Cannot convert unsupported type
JSON Schema type not recognized by Avro
fix
Ensure type is one of: null, boolean, int, long, float, double, bytes, string, record, enum, array, map, union, fixed.
Schema must be dereferenced before conversion
Input contains unresolved $ref
fix
Resolve all references using json-schema-ref-parser or similar before conversion.
Module not found: Can't resolve 'tslib'
Missing peer dependency
fix
Install tslib: npm install tslib
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
tslibrequiredRuntime dependency for TypeScript helpers
Agent activity
10 hits · last 30 days
node
8
Amazon
2
Resources
json-schema-to-avro — npm install json-schema-to-avro · libregistry