buglabs / node-xml2json

Converts XML to JSON using node-expat
809 stars 210 forks source link

tojson error #115

Open wilywork opened 8 years ago

wilywork commented 8 years ago

error in json result, instead of null appears an object.

xmlExample = "test"; xmlExample.toJson(xmlExample); // result
{ "xml":{ "text":"teste", "text2":{} <== Bug, should be null } }

c4milo commented 8 years ago

With this code:

var parser = require('./index');

// xml to json
var xml = "test";
console.log("input -> %s", xml)
var json = parser.toJson(xml);
console.log("to json -> %s", json);

var xml = parser.toXml(json);
console.log("back to xml -> %s", xml)

I get

input -> test
to json -> {}
back to xml ->
c4milo commented 8 years ago

Which seems to be correct to me. Why should it be "null"?

wilywork commented 8 years ago
var valid = parser.toJson("<xml><test></test></xml>");
if(valid.xml.test){ //return true,  valid.xml.test = { }
 console.log(valid.xml.test) // output [object Object]
}

...