Translate XML Schema into equivalent JSON Schema
Prolog JavaScript Shell


Translate an XML Schema into equivalent JSON Schema based on SWI-Prolog and Constraint Handling Rules (CHR). For usage directly in Prolog or node.js.


First, make sure SWI-Prolog is installed. This module expects the swipl binary to be in PATH somewhere. In other words, type this:

$ swipl

If that works, so will xsd2json.

Using npm, you can install xsd2json by calling this:

$ npm install -g xsd2json

Or simply clone this repository:

$ git clone

Usage as CLI

If you install xsd2json via npm it will create a new command xsd2json:

$ xsd2json /path/to/your.xsd > /created/schema.json

Usage with node.js

The xsd2json module can be used programmatically as function or stream:

var xsd2json = require('xsd2json');
var filename = 'test.xsd';

// use as stream: Read from stdin

// use as function
xsd2json(filename, function(err, schemaObject) {
  console.log(JSON.stringify(schemaObject, null, 2));

Usage with Prolog

xsd2json provides a predicate xsd2json(+XSD,-JSON), which holds for a given XML Schema (either file path, URL or stream). For instructions on how to use xsd2json programmatically in Prolog, have a look at the Prolog module's Readme.


This tool has been developed as part of my Bachelor's Thesis at University of Ulm, Germany. The thesis (PDF) explains the general idea of the translation process via Prolog and Constraint Handling Rules (CHR). It also contains tabular and graphical representations of the implemented translations of XML Schema fragments. A shorter explanation of the translation process can be found in the CHR Workshop paper "From XML Schema to JSON Schema: Translation with CHR".

Project Structure

xsd2json is developed in a test-driven way. This reflects in the project's folder structure, too: The /lib-pl directory contains the Prolog and CHR stuff while you will find the TAP testing framework implemented in node.js under /test. Both directories contain their own Readme-File that explain their usage.