Skip to content
Switch branches/tags
Go to file
Cannot retrieve contributors at this time

JXT: JSON/XML Translation

Turn your XML into the JSON you always knew it could be.

Working with XML can be tedious, but many XML to JSON converters leave you with a DOM dump which is just as annoying to traverse and work with. JXT allows you to import XML into dev-friendly JSON that matches what you would have otherwise used, and then export that data back into XML when needed.

Basic Usage

import { JXT } from 'stanza';
const registry = new JXT.Registry();

    namespace: 'jabber:client',
    element: 'message',
    path: 'message',
    fields: {
        to: JXT.attribute('to'),
        from: JXT.attribute('from'),
        subject: JXT.childText(null, 'subject'),
        body: JXT.childText(null, 'body')

const xml = JXT.parse(`
  <message xmlns="jabber:client" to="">
    <body>giving a demo of jxt</body>

const msg = registry.import(xml);
// {to: '', body: 'giving a demo of jxt'}

const xml2 = registry.export('message', {
    to: '',
    body: 'giving a demo of jxt'
// '<message xmlns="jabber:client" to=""><body>giving a demo of jxt</body></message>'