yajc
raw JSON → 1.0.0 verified Fri May 01 auth: no javascript
yajc (Yet Another Json Transpiler) v1.0.0 generates Java POJOs, Go structs, and other data models from JSON input. It provides a simple CLI and programmatic API for converting JSON schemas into strongly-typed language constructs. Released as a stable single version with no ongoing updates. Differentiators: lightweight, no runtime dependencies beyond Node.js, and supports multiple output languages from a single tool.
Common errors
error Cannot find module 'yajc' ↓
cause Attempting to require() the package in CommonJS; yajc is ESM-only.
fix
Use import instead of require, or run in an ESM context.
error yajc: command not found ↓
cause yajc not installed globally; CLI bin not in PATH.
fix
Run 'npm install -g yajc' to install globally.
error TypeError: convert is not a function ↓
cause Importing default instead of named export 'convert'.
fix
Use 'import { convert } from 'yajc'' instead of 'import yajc from 'yajc''.
Warnings
gotcha yajc does not validate JSON input; invalid JSON may produce broken output without error. ↓
fix Pre-validate JSON using JSON.parse() before passing to yajc.
gotcha The generated code may not include imports or package declarations for all languages; you must add them manually. ↓
fix Wrap output in necessary boilerplate (e.g., package, imports).
gotcha CLI global install required for command-line usage; local install only provides programmatic API. ↓
fix Run 'npm install -g yajc' for CLI, or use programmatic API from local install.
Install
npm install yajc yarn add yajc pnpm add yajc Imports
- default wrong
const yajc = require('yajc')correctimport yajc from 'yajc' - convert wrong
import convert from 'yajc'correctimport { convert } from 'yajc' - yajc (types)
import type { Options } from 'yajc'
Quickstart
import { convert } from 'yajc';
const json = '{"name": "Alice", "age": 30}';
const result = convert(json, { language: 'go', package: 'main' });
console.log(result);
// Output:
// type AutoGenerated struct {
// Name string `json:"name"`
// Age int `json:"age"`
// }