Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ernieIzde8ski opened this issue Sep 22, 2023 · 1 comment
Open

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

ernieIzde8ski opened this issue Sep 22, 2023 · 1 comment

Comments

@ernieIzde8ski
Copy link

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):

  • OS: Windows
  • Python version 3.11
  • json2xml.__version__: 4.0.0
@ernieIzde8ski
Copy link
Author

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant