How to Convert JSON to XML in Node.js

Cloudmersive
2 min readDec 21, 2022

--

Finding a quick, easy way to convert JSON data to XML format will save you a lot of time. Using the below code, you can call our JSON to XML conversion API for free, which will quickly convert a JSON object into XML format and return a body of XML text. Just follow brief instructions below to copy & paste from the below Node.js code examples, then authenticate the call with a free-tier Cloudmersive API key (get one by registering a free account here), and you’re all done.

Let’s first install the SDK by running the below command:

npm install cloudmersive-convert-api-client --save

We can also add this snippet to our package.json instead:

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

Lastly, let’s call the function below, including our JSON object in the var jsonObject field:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;

// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';



var apiInstance = new CloudmersiveConvertApiClient.ConvertDataApi();

var jsonObject = null; // Object | Input JSON Object to convert to XML


var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.convertDataJsonToXml(jsonObject, callback);

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet