sanand0 / xmljson

xmlsjon converts XML into Python dictionary structures (trees, like in JSON) and vice-versa.
MIT License
122 stars 33 forks source link

Fix to avoid invalid JSON output #24

Closed dagwieers closed 6 years ago

dagwieers commented 7 years ago

This PR fixes a few issues:

This fixes #23

PS Do we have a location for adding unit-tests so we can test whether XMLData works as designed ?

sanand0 commented 7 years ago

@dagwieers - the returned object is a Python object. Serializing into JSON returns a valid JSON object. For example:

>>> json.dumps(xmljson.badgerfish.data(fromstring('<root x="nan"/>')))
'{"root": {"@x": NaN}}'
>>> json.dumps(xmljson.badgerfish.data(fromstring('<root x=""/>')))
'{"root": {"@x": null}}'

The results are valid JSON. I don't think this PR is required... unless I'm missing something?

dagwieers commented 7 years ago

@sanand0 NaN and infinity are not accepted by the JSON standard, but apparently the python json library setsallow_nan=True. See: https://stackoverflow.com/questions/6601812/sending-nan-in-json

But apart from trying to fix that, this PR fixes a few other things, like empty strings should not be converted to null IMO.