Closed SaraFarron closed 1 year ago
Thanks for reporting the issue. I will look into it and try to implement a fix for it.
@SaraFarron I think I know what's going wrong. I am confirm that nothing goes wrong if you JSON is a valid string.
def test_dict_attr_crash(self):
data = data = {
"product": {
"@attrs": {
"attr_name": "attr_value",
"a": "b"
},
"@val": [],
},
}
result = json2xml.Json2xml(data).to_xml()
dict_from_xml = xmltodict.parse(result)
assert dict_from_xml["all"]["product"]["@attr_name"] == "attr_value"
assert dict_from_xml["all"]["product"]["@a"] == "b"
I added your JSON into a test and it just seems to work.
The issue with your JSON string is that you are adding the attrs in a '
quote.
{
"product": {
"@attrs": {
'attr_name': 'attr_value"'
},
"@val": [],
},
}
If you fix that, the data is like this:
{
"product": {
"@attrs": {
"attr_name": "attr_value"
},
"@val": [],
},
}
It would just work
Hm, I was thinking about json2xml replacing such characters with \"
or "e
but on second thought you might be right that user should pass a valid json in the first place. Thanks for answering!
Describe the bug An error occurs if trying to add a custom attributes with " inside
To Reproduce Steps to reproduce the behavior:
Gives
For some reason
@attrs
key is popped out of the dictionary, which might be not an expected behaviorExpected behavior An xml-like string
Desktop (please complete the following information):