json-xml-converter module
The json-xml-converter module provides APIs for conversion between JSON and XML objects.
You can convert JSON objects to XML format and XML objects to JSON format.
Access this module with a require statement like var converter =
require('json-xml-converter').
converter.toJSON()
Convert a xmlDoc document to a jsonDoc document.
- Syntax
converter.toJSON(type,document)- Parameters
-
- type
- The supported conversion type. Only
badgerfishis supported. - document
- The JSON formatted DOM (
xmlDoc) to be converted to a JSON object (jsonDoc).
- Guidelines
- If the conversion fails, an exception is raised.
converter.toXML()
Convert a jsonDoc document to a xmlDoc document.
- Syntax
converter.toXML(type,document)- Parameters
-
- type
- The supported conversion type. Only
badgerfishis supported. - document
- The JSON object (
jsonDoc) to be converted to a JSON representation of an XML document (xmlDoc).
- Guidelines
- If the conversion fails, an exception is raised.
- Example
- An example that shows how to convert XML and BadgerFish formatted JSON
objects.
var converter = require('json-xml-converter'); var jsonDoc = {"hello": {"$": "world"}}; //<hello>world</hello> var xmlDoc = converter.toXML('badgerfish', jsonDoc); var result = converter.toJSON('badgerfish', xmlDoc);