I have a json object with the following structure:
[
{
"filters": [
{
"name": "category",
"list": [
{
"category-abc": {
"title": "abc",
"number": "2"
}
},
{
"category-def": {
"title": "def",
"number": "1"
}
}
]
},
{
"name": "topic",
"list": [
{
"topic-abc": {
"title": "abc",
"number": "6"
}
},
{
"topic-def": {
"title": "def",
"number": "5"
}
}
]
},
}
]
The list is actually much longer, with many name | list pairs. I am looking to grab each list as I iterate along an array of list names, but don’t want to walk that list every time, so I want to grab the list by name.
Something like this:
filters['topic'][0].title
But that won’t work, as there’s the “name” key there. Is there any way to do this without conditionals?
I think this is what you want (it assumes
datacontains the original JSON object):