vinitkumar / json2xml

json to xml converter in python3
https://json2xml.readthedocs.io/
Other
98 stars 32 forks source link

@attrs keyword does not work at the root level #187

Open ernieIzde8ski opened 11 months ago

ernieIzde8ski commented 11 months ago

Describe the bug

Attempting to declare attributes for the 'wrapper' node results in them being added as their own nodes.

To Reproduce

Steps to reproduce the behavior:

from json2xml.json2xml import Json2xml
from json2xml.utils import readfromstring

data = {
    "@attrs": {
        "a": "b"
    }
}
result = Json2xml(data).to_xml()
print(result)

Result:

<?xml version="1.0" ?>
<all>
        <key name="@attrs" type="dict">
                <a type="str">b</a>
        </key>
</all>

Expected behavior

It should print something more like this:

<?xml version="1.0" ?>
<all a="b"/>

Desktop (please complete the following information):

ernieIzde8ski commented 11 months ago

Might want to close this issue since there is a convenient workaround

data = { ... }
data = {"all": data}
result = Json2xml(data, root=False).to_xml()