I am using the following code to convert xml to json :-
var parseString = require('xml2js').parseString;
var xml = "<root><param_name>Hello</param_name><param_entry> xml2js! </param_entry> </root>";
parseString(xml, {trim: true},function(err,result){
console.dir(JSON.stringify(result));
});
It is returning the following result -
{
"root":{
"param_name":[
"Hello"
],
"param_entry":[
" xml2js!"
]
}
}
It is returning value of as collection of objects i.e. as "param_name":[
"Hello"
].
But I want it as a simple key and value form. That is my resultant JSON should look like -
{
"root":{
"param_name":
"Hello"
,
"param_entry":
" xml2js!"
}
}
What is it that is going wrong here ?