Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @raydeck/jxon with all npm packages installed. Try it out:

var jxon = require("@raydeck/jxon")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@raydeck/jxon v3.0.1

A complete, bidirectional, JXON library

JXON Build Status

A complete, bidirectional, JXON (lossless JavaScript XML Object Notation) library. Packed as UMD.

Implementation of Mozilla's JXON code. Head over to MDN for Documentation.


{name: 'myportal'} 

{user: {
    username: 'testUser1',
    password: 'yolo',
    enabled: true

{tag: {
    $type: 'regular'
    $blacklist: false
    _: 'Backbase'
<tag type="regular" blacklist="false">Backbase</tag>

{dogs: {
    name: ['Charlie', {$nick: 'yes', _:'Mad Max'}]
    <name nick="yes">Mad Max</name>



Overrides default configuration properties

  • cnf - Object with configuration properties.


valueKey: '_',
attrKey: 'apos;,
attrPrefix: 'apos;,
lowerCaseTags: false,
trueIsEmpty: false,
autoDate: false,
ignorePrefixedNodes: false,
parseValues: false,
parserErrorHandler: undefined


Converts XML string to JS object.

  • xmlString - XML string to convert to JXON notation JS object


Converts JS object to XML string.

  • obj - JS object in JXON notation to convert to XML string

.xmlToJs(xmlDocument, verbosity, freeze, nestedAttributes)

Converts XML document to JS object. Alias:

  • xmlDocument - The XML document to be converted into JavaScript Object.
  • verbosity - Optional verbosity level of conversion, from 0 to 3. It is almost equivalent to our algorithms from #4 to #1 (default value is 1, which is equivalent to the algorithm #3).
  • freeze - Optional boolean expressing whether the created object must be freezed or not (default value is false).
  • nestedAttributes - Optional boolean expressing whether the the nodeAttributes must be nested into a child-object named keyAttributes or not (default value is false for verbosity levels from 0 to 2; true for verbosity level 3).


var myObject =;

.jsToXml(obj, namespaceURI, qualifiedNameStr, documentType)

Converts JS object to XML document. Alias: JXON.unbuild

  • obj - The JavaScript Object from which you want to create your XML Document.
  • namespaceURI - Optional DOMString containing the namespace URI of the document to be created, or null if the document doesn't belong to one.
  • qualifiedNameStr - Optional DOMString containing the qualified name, that is an optional prefix and colon plus the local root element name, of the document to be created.
  • documentType - Optional DocumentType of the document to be created. It defaults to null.


var myObject = JXON.unbuild(myObject);


Wrapper over DOMParser.parseFromString, converts string to XML document.

  • xmlString - XML string to convert to XML document


Wrapper over XMLSerializer.serializeToString, converts XML document to string.

  • xmlObj - XML document to convert to XML string

.each(obj, callback[, thisArg])

Helper method to iterate node(s).
In case that there is only one children node, JXON will return object. For multiple children it will return array. This method will always iterate nodes as array.

  • obj - array or object to iterate
  • callback - function to execute for each element
  • thisArg - optional. Value to use as this when eecuting callback


var jx = jxon.stringToJs('<val>foo</val>');
jxon.each(jx.val, function(val) {
    assert(val, 'foo');



changes from version 1.x to 2.0 include:

  • (breaking) more usefull default settings (see above)
  • (breaking) stringify Dates to ISO format instead of GMT
  • improved xml namespace handling on node and browsers
  • renamed main source file to jxon.js


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free