npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xsd2json

v1.12.22

Published

Translate an XML Schema into equivalent JSON Schema

Downloads

392

Readme

xsd2json

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.

Installation

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 and manually run the preinstall scripts to create pre-compiled Prolog files:

git clone https://github.com/fnogatz/xsd2json.git
npm run preinstall

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
xsd2json(filename)
  .pipe(process.stdout);

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

In addition to the command line options provided by the Prolog module, there are the following options available in the node.js module:

  • noExe: true | false (default): Use the native Prolog interface instead of the pre-compiled cli.exe. This might be useful for MacOS users (see issue #87 for more details).
  • swi: 'swipl' (default): Executable to call SWI-Prolog.

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.

Background

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.

Known Bugs

xsd2json's tests are always executed using the latest stable release of SWI-Prolog. Make sure to have the latest version installed before you file a bug.

Apparently SWI-Prolog of version 7.2.x ships with a bug in the CHR implementation. Use version 7.4 or higher instead.

Alternatives