Jsonix Schema Compiler
raw JSON → 2.3.9 verified Fri May 01 auth: no javascript maintenance
Jsonix Schema Compiler is a Java-based tool that generates Jsonix mappings and JSON Schema definitions from XML Schema (XSD) files. Version 2.3.9 is the latest stable release, with active but infrequent updates. It is a companion to the Jsonix library for XML-JSON conversion. Key differentiators: handles complex XML Schema features like enums, minOccurs/maxOccurs, xs:duration, and built-in type detection. Requires Java runtime to run, integrates via Java JAR or Maven plugin. Unlike pure JavaScript alternatives, it provides full XSD compliance. Does not support XML Schema 1.1 and has no TypeScript type generation.
Common errors
error Error: Unable to access jarfile node_modules/jsonix-schema-compiler/lib/jsonix-schema-compiler-full.jar ↓
cause JAR file not found or path incorrect.
fix
Verify that jsonix-schema-compiler is installed and the JAR exists. Check exact filename in lib/ directory.
error Error: Could not find or load main class org.jvnet.jaxb2_commons.xjc.XJCTask ↓
cause Running an older version of the JAR or incorrect invocation without main class.
fix
Use the correct JAR file:
jsonix-schema-compiler-full.jar which is an executable JAR. Do not invoke without -jar. error ReferenceError: MyMapping is not defined ↓
cause Generated mapping file is not imported or path is wrong.
fix
Ensure the generated mapping file path matches the import statement. The compiler outputs to a 'mapping' directory by default.
Warnings
gotcha This package is a Java JAR, not a JavaScript module. Installing via npm does not provide a JavaScript API; you must invoke the JAR via command line or Java API. ↓
fix Use the CLI command `java -jar node_modules/jsonix-schema-compiler/lib/jsonix-schema-compiler-full.jar`. Do not expect to import anything from this package in JavaScript.
deprecated Usage of npm `prepublish` script is considered an antipattern. Since npm v5, `prepublish` runs on both `npm install` and `npm publish`, causing unintended generation. Use `prepare` instead. ↓
fix Change scripts from `prepublish` to `prepare` in package.json.
gotcha Java Runtime Environment (JRE) is required to run the compiler. Node.js only, without Java, will fail. ↓
fix Ensure Java 8+ is installed and available in PATH.
breaking Version 2.3.7 introduced `required`, `minOccurs`, and `maxOccurs` in generated mappings. Mappings generated with older versions may produce different output when used with a newer Jsonix runtime. ↓
fix Regenerate mappings after upgrading to 2.3.7+ and use compatible Jsonix version.
gotcha The compiler JAR filename has changed across versions. Some versions use `jsonix-schema-compiler-full.jar`, others may have different names. ↓
fix Check the actual JAR file in `node_modules/jsonix-schema-compiler/lib/` after install and adjust command accordingly.
Install
npm install jsonix-schema-compiler yarn add jsonix-schema-compiler pnpm add jsonix-schema-compiler Imports
- Default wrong
const Default = require('jsonix')correctimport { Default } from 'jsonix' - Marshaller wrong
const Marshaller = require('jsonix').Marshallercorrectimport { Marshaller } from 'jsonix' - Unmarshaller wrong
const Unmarshaller = require('jsonix').Unmarshallercorrectimport { Unmarshaller } from 'jsonix' - compile wrong
import { compile } from 'jsonix-schema-compiler'correct// not a JS import; use CLI: java -jar jsonix-schema-compiler-full.jar
Quickstart
// First, install jsonix-schema-compiler and jsonix
// npm install jsonix-schema-compiler jsonix
// Then in package.json scripts:
{
"scripts": {
"prepublish": "java -jar node_modules/jsonix-schema-compiler/lib/jsonix-schema-compiler-full.jar schema.xsd"
}
}
// Run npm run prepublish to generate mapping file jsonschema.js
// Then in your code:
import { Default, Marshaller, Unmarshaller } from 'jsonix';
import { MyMapping } from './mapping/MyMapping.js';
const context = new Default([ MyMapping ]);
const marshaller = new Marshaller(context);
const unmarshaller = new Unmarshaller(context);
// Example: marshal an object to XML
const obj = { name: 'John', age: 30 };
const xml = marshaller.marshalString(obj);
console.log(xml);
// Example: unmarshal XML string
const result = unmarshaller.unmarshalString(xml);
console.log(result);