I am using AngularJS template to show a JSON as a list/tree structure.
My JSON depth is unknown. In most of the cases my code works. There is just one case I have encountered so far that does not work.
My JSON sample:
[
{
"type":"image",
"bitmapname":{
"text":"Image_12.bmp"
},
"command":[
{
"type":"close",
"text":"1234"
},
{
"type":"place",
"text":"company"
},
{
"type":"key",
"key": "Tab"
},
{
"type":"keyboard",
"text":"welcome",
"command": [
{
"type":"open",
"text":"1234"
},
{
"type":"home",
"text":"company"
}
]
}
]
},
{
"type":"image",
"bitmapname":{
"text":"image_14.bmp"
},
"command":{
"type":"move",
"text":"right"
}
}
]
The output is below:

AngularJS code:
<script type="text/ng-template" id="xml.html">
<!-- XML is coming from controller as a JSON shown in my sample -->
<ul>
<li ng-repeat="item in XML">
[[ item["type"] ]]
<div ng-include=" 'xml.html' "
onload="XML = item.command">
</div>
</li>
</ul>
</script>
<div ng-include=" 'xml.html' ">
As you may noticed last list item is empty because that "command" is not an Array
I am trying to create a recursive function that will go through the JSON and create arrays on one element "command": [{...}] in places where I have "command": {...}
Can anyone suggest a solution that will convert the object to array of object wherever I have length-one object?
NOTE
I have no control over JSON being sent from Django backed. Python is using xmltodict extension to convert XML to Dictionary. Whenever XML tags have no children it does not create a list. It only creates a dictionary.
.commandproperties? The best solution here would be to start off with a consistent data format and not to find workarounds for an inconsistent one.