I would recommend to convert your JSON file text and that is possible by below sort way:
//Your JSON file data...
var returnJSONFile = {
"cancelled": false,
"text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<PrintLetterBarcodeData uid=\"345135084445\" name=\"Venkatasiva M\" gender=\"M\" yob=\"1985\" co=\"S/O Narayana\" vtc=\"Pamidi vari palem\" dist=\"Guntur\" state=\"Andhra Pradesh\" pc=\"522112\"/>",
"format": "QR_CODE"
};
//Object Initialization...
var x2js = new X2JS();
//Convert XML to JSON...
var xml2Json = JSON.stringify(x2js.xml_str2json(returnJSONFile.text));
alert(xml2Json);
Please check my JSFIDDLE for more understanding.
I accomplish this by using x2js library.
This library provides XML to JSON (JavaScript Objects) and vice versa javascript conversion functions. The library is very small and doesn't require any other additional libraries.
API functions
- new X2JS() - to create your instance to access all library
functionality. Also you could specify optional configuration options here
- X2JS.xml2json - Convert XML specified as DOM Object to JSON
- X2JS.json2xml - Convert JSON to XML DOM Object
- X2JS.xml_str2json - Convert XML specified as string to JSON
- X2JS.json2xml_str - Convert JSON to XML string
Hope this help you well!