I have a data object like this:
data = {
'props': {
'items': [
{'name': 'a', 'content': 'plain'},
{'name': 'b', 'content': {'id': 'x'}},
{'name': 'c', 'content': {'id': 'y'}},
]
}
}
Using glom, I want to get x which is the value of id for the item with name equal to b.
So far, I have this:
from glom import glom
from glom import SKIP
glom(data, ('props.items', [lambda i: i if i['name']=='b' else SKIP]))
Which returns:
[{'name': 'b', 'content': {'id': 'x'}}]
I can't figure out what spec (in glom parlance) to use to extract the only element in the returned list and then the value of id.
I could call glom twice:
glom(glom(data, ('props.items', [lambda i: i if i['name']=='b' else SKIP]))[0], 'content.id')
But I figured there should be a way of doing it in one call. Any ideas on how to achieve this?