Registry / serialization / eth-json-schema-transpiler

eth-json-schema-transpiler

JSON →
library0.0.0-developmentjsnpmunverified

A dev tool that converts JSON Schemas into type definitions for multiple languages including TypeScript, Go, Rust, and Python. Version 0.0.0-development is in early development with limited updates. It features automatic cycle detection, reference resolution, and deterministic title generation. Key differentiators: minimal dependencies, synchronous execution, and browser support via the web demo. The package generates one type alias per schema and includes documentation annotations.

npm install eth-json-schema-transpiler
INSTALL
IMPORT
SIG · ETH-JSON-SCHEMA-TR
E
eth-json-schema-transpiler
serializationjavascriptv0.0.0-development
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
import JsonSchemaTranspiler from 'eth-json-schema-transpiler'
import { JsonSchemaTranspiler } from 'eth-json-schema-transpiler'
The package exports a default class, not named exports. CommonJS users should use require().default.
JsonSchemaTranspiler
import JsonSchemaTranspiler from 'eth-json-schema-transpiler'
const JsonSchemaTranspiler = require('eth-json-schema-transpiler')
CommonJS require returns the module, so you need .default: const JsonSchemaTranspiler = require('eth-json-schema-transpiler').default
toTypescript
const transpiler = new JsonSchemaTranspiler(schema); transpiler.toTypescript()
JsonSchemaTranspiler.toTypescript(schema)
toTypescript is an instance method, not static.

Shows basic usage: import default, instantiate with schema, call toTypescript method.

import JsonSchemaTranspiler from 'eth-json-schema-transpiler'; const mySchema = { title: 'Person', type: 'object', properties: { name: { type: 'string' }, age: { type: 'integer' } }, required: ['name'] }; const transpiler = new JsonSchemaTranspiler(mySchema); console.log(transpiler.toTypescript()); // Output: type Person = { name: string; age?: number; };
Debug
Known issues
breakingUpgrading from v0.0.1 to v0.0.2 changes default output format for Go and Rust outputs. TypeScript output now includes optional properties.
fix
Review generated types and adjust downstream code if needed.
affects: >=0.0.2
deprecatedThe .to('language') shorthand is deprecated in favor of explicit language methods (toTypescript, toGo, toRust, toPython).
fix
Use toTypescript() instead of to('typescript').
affects: >=0.0.3
gotchaJSON Schema $ref references may not be resolved in browser environments without bundler configuration for json-schema-ref-parser.
fix
Ensure your bundler (e.g., webpack) includes Node.js polyfills for path and url modules.
affects: all
gotchaThe package is case-sensitive about language names: 'typescript', 'go', 'rust', 'python' are supported. 'TypeScript' or 'py' will throw an error.
fix
Use exact lowercase names when calling .to(), or use the dedicated methods.
affects: all
Errors
Common errors & fixes
TypeError: JsonSchemaTranspiler is not a constructor
Importing as named export instead of default, or using CommonJS without .default
fix
Use import JsonSchemaTranspiler from 'eth-json-schema-transpiler' (ESM) or const JsonSchemaTranspiler = require('eth-json-schema-transpiler').default (CJS)
Error: Invalid schema: schema must be an object
Passing a JSON string instead of a parsed object to the constructor
fix
Parse the JSON string first: JSON.parse(schemaString)
TypeError: transpiler.to is not a function
Using an outdated version that does not have the .to() method, or importing incorrectly
fix
Update to latest version. If using CommonJS, ensure you used .default.
Error: Unsupported language 'python3'
Providing an unsupported language name to .to()
fix
Use one of: 'typescript', 'go', 'rust', 'python'
Upgrade
Version history
0.0.0-developmentlatest on npm
Audit
Dependencies
@json-schema-tools/meta-schemarequiredProvides meta-schema validation and referencing used internally
json-schema-ref-parserrequiredHandles JSON Schema $ref resolution and bundling
Agent activity
2 hits · last 30 days
node
2
Resources
eth-json-schema-transpiler — npm install eth-json-schema-transpiler · libregistry