buglabs/node-xml2json — Issue #8: $t Inconsistency
Author: rclark
Created: 2011-10-21 23:50:52+00:00
State: open

It seems like
myJsonThing == parser.toJson(parser.toXML(myJsonThing));
should be true, right?

The trouble is some inconsistency in the way XML element content is converted to JSON. In the case where an XML element has other attributes AND a value, the value becomes "$t": "elementValue". However when the XML element has no attributes, the JSON simply becomes "elementName": "elementValue".

For example:
> myThing = {myThing: { "$t": "five" } }
{ myThing: { '$t': 'five' } }
> parser.toXml(myThing);
'five'
> parser.toJson(parser.toXml(myThing));
'{"myThing":"five"}'

And in reverse:
> xml = 'five'
'five'
> parser.toJson(xml);
'{"myThing":"five"}'
> parser.toXml(parser.toJson(xml));
' myThing=\'five\'>'