kislyuk / yq

Command-line YAML, XML, TOML processor - jq wrapper for YAML/XML/TOML documents
https://kislyuk.github.io/yq/
Apache License 2.0
2.57k stars 82 forks source link

Add support for xmltodict force_list definition for xq CLI #95

Closed nohal closed 4 years ago

nohal commented 4 years ago

By default xmltodict does not return list in case only one element is present, which may lead to problems like this:

test.xml

<a>
<b/>
</a>

test1.xml

<a>
<b/>
<b/>
</a>

xq . test.xml produces

{
  "a": {
    "b": null
  }
}

while xq . test1.xml produces

{
  "a": {
    "b": [
      null,
      null
    ]
  }
}

The patch implements a new --xml-force-list switch, which allows forcing the use of arrays for defined tags even if only one occurence is present in the XML source:

xq --xml-force-list b . test.xml
{
  "a": {
    "b": [
      null
    ]
  }
}
kislyuk commented 4 years ago

Thanks for your contribution. I'll roll a release with this change shortly. A test would be nice to add as well.

kislyuk commented 4 years ago

Released in v2.10.1.