I parsed a XML file and retrieved the following JSON-object. The issue is that there are dashes in the json, which causes problems iterating through the object. I can not get rid off them unfortunately.
$(function() {
let json = JSON.parse('{"app-app":{"$":{},"notneeded":"123","mapped":{"$":{},"match-match":[{"$":{},"name":"Foo 1","url":"/Bar 1"},{"$":{},"name":"Foo 2","url":"/Bar 2"},{"$":{},"name":"Foo 3","url":"Bar 3"}]},"Nothing":"123"}}');
var foo = Object.keys(json['app-app']['mapped']['match-match']).length;
for (var i = 0; i < foo; i++) {
console.log(json['app-app']['mapped']['match-match'][i].name);
console.log(json['app-app']['mapped']['match-match'][i].url);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
I would like to iterate through the object and extract every "match" children. Something like this:
return [
{
name: 'Foo 1',
url: 'Bar 1'
},
[...]
]
Thanks you in advance.
value.app.mapped.match