Closed joaociocca closed 1 year ago
You're looking for the force_list parameter in xmltodict (https://github.com/martinblech/xmltodict/blob/fe3a37571e3867845b29e3c14ccc88186cbe379d/xmltodict.py#L270-L276). yq does not currently provide direct access to this parameter, but it seems like there's a legitimate use for it so we can look into adding it.
is there a workaround I can do in the mean time?
No.
Turns out I had already integrated force_list but just forgot about it. You can use xq --xml-force-list ELEMENT_NAME
to accomplish this.
When I try to parse an nmap XML result file through
xq
I'm having one difficulty. I'll start with the example:I can get to the
port[]´ level just fine with
xq -r '.nmaprun.host.ports.port[]', but then xq will make the
.scriptfrom
port[0]an object, and the
.scriptfrom
port[1]` an array.My main goal here is to check if
.script
contains anelem
with@key
value ofredirect_url
, which I know how to do... but I can't seem to correctly access when.script
can be an object or an array.I could go the long way (since this will be a bash script) and first identify if there is just a single type of
.script
or two, and make differentxq
calls accordingly, but I was wondering if there's a way to deal with this straight on a jq query level.--edit
oh gods, I just realized the same happens with
.elem
. They can be an object if there's a single<elem>
inside<script>
or an array if there are multiple O.o--edit2
JFC elem can also be a string in case of
<elem>text</elem>
... this is a nightmare O.o