How to convert JSON to XML format in Node.JS

Setting up format conversions in Node.JS is definitely not a fun way to spend an afternoon. Good thing we already took care of it for you. That’s right, just a couple minutes from now, you’ll be done with the whole mess and able to move on to more interesting endeavors. Let’s take a look.

Place this dependency reference in your package.json to install our API client.

"dependencies": {
"cloudmersive-convert-api-client": "^2.1.6"
}

Now convertDataJsonToXml can be implemented using the following sample code.

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.ConvertDataApi();var jsonObject = null; // Object | Input JSON to convert to XMLvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.convertDataJsonToXml(jsonObject, callback);

Done. Yup, super easy. All of our APIs work like this, and can be used to take the pain away from a very wide array of tasks, including optical character recognition and facial detection.

Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store