Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
History
=======

3.17.1 / 2022-04-20
===================

* fix: issue with wrong output for boolean list
* fix: pull requests also trigger action runs

3.17.0 / 2022-04-18
===================

Expand Down
5 changes: 5 additions & 0 deletions examples/booleanjson2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"boolean_list": [true, false],
"number_array": [1, 2, 3],
"string_array": ["a", "b", "c"]
}
2 changes: 1 addition & 1 deletion json2xml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = """Vinit Kumar"""
__email__ = "mail@vinitkumar.me"
__version__ = "3.17.0"
__version__ = "3.17.1"
9 changes: 6 additions & 3 deletions json2xml/dicttoxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def convert(obj, ids, attr_type, item_func, cdata, item_wrap, parent="root"):

LOG.info(f'Inside convert(). obj type is: "{type(obj).__name__}", obj="{str(obj)}"')


item_name = item_func(parent)

# since bool is also a subtype of number.Number and int, the check for bool
Expand Down Expand Up @@ -265,7 +266,11 @@ def convert_list(items, ids, parent, attr_type, item_func, cdata, item_wrap):
f'Looping inside convert_list(): item="{str(item)}", item_name="{item_name}", type="{type(item).__name__}"'
)
attr = {} if not ids else {"id": f"{this_id}_{i + 1}"}
if isinstance(item, (numbers.Number, str)):

if isinstance(item, bool):
addline(convert_bool(item_name, item, attr_type, attr, cdata))

elif isinstance(item, (numbers.Number, str)):
if item_wrap:
addline(
convert_kv(
Expand Down Expand Up @@ -298,8 +303,6 @@ def convert_list(items, ids, parent, attr_type, item_func, cdata, item_wrap):
)
)

elif isinstance(item, bool):
addline(convert_bool(item_name, item, attr_type, attr, cdata))

elif isinstance(item, dict):
item_dict_str = convert_dict(
Expand Down
9 changes: 9 additions & 0 deletions tests/test_json2xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,12 @@ def test_read_boolean_data_from_json(self):
dict_from_xml = xmltodict.parse(result)
assert dict_from_xml["all"]["boolean"]["#text"] != 'True'
assert dict_from_xml["all"]["boolean"]["#text"] == 'true'


def test_read_boolean_data_from_json2(self):
"""Test correct return for boolean types."""
data = readfromjson("examples/booleanjson2.json")
result = json2xml.Json2xml(data).to_xml()
dict_from_xml = xmltodict.parse(result)
assert dict_from_xml["all"]["item"][0]["#text"] != 'True'
assert dict_from_xml["all"]["item"][0]["#text"] == 'true'
Loading