martinblech / xmltodict

Python module that makes working with XML feel like you are working with JSON
MIT License
5.49k stars 462 forks source link

List type object with single parameter is being converted into wrong format #271

Closed mdakilansari closed 2 years ago

mdakilansari commented 3 years ago

Format is wrong after conversion of List object with single value.

example:

{ "name": "ParameterName", "p": "10638" }

Expected:

{ "name": "ParameterName", "p": ["10638"] }

Please look into this issue. Attaching Sample XML snip for reference. image

Thank you in advance.

deridiot commented 2 years ago

as i stumbled over this as well let me point you and other people looking for this to the correct place:

https://github.com/martinblech/xmltodict/blob/master/xmltodict.py#L266

set the force_list parameter on the parse method to either True to always return lists for all elements or provide a tuple with the tag names you do want as lists. works like a charm... just very much undocumented unless we consider the code documenting itself ;)