0

I am unable to get callback in JSON format when trying to convert XML to JSON in AWS Lambda and API gateway integration.

Code :

enter code here

exports.handler = (event, context, callback) => {
var parseString = require('xml2js').parseString;
var xml = "<Name>Sayyed Abbas</Name>";
parseString(xml, function (err, result) {
var r = JSON.stringify(result)
console.dir(r);
callback(null,event.r);
});
};

The Output, I see in AWS is below. enter image description here

1 Answer 1

4

Use toJson method in xml2json module. It works perfectly for me.

let xmlParser = require('xml2json');
let xml = "<Name>Sayyed Abbas</Name>";
console.log('JSON output', xmlParser.toJson(xml));
Sign up to request clarification or add additional context in comments.

3 Comments

Anytime. Incase if my answer helped you to solve the problem accept it as the answer. Thank you.
Where did you define xml2json?
It is a npm module(npmjs.com/package/xml2json). Sorry that I didn't mention it before since it has already been used in the question. I updated my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.