Given the input:
data = [{'leagues': [{'id': 2294162, 'sport': 'S'}, {'id': 8541851, 'sport': 'S'}]},
{'leagues': []},
{'leagues': [{'id': 2228013, 'sport': 'B'}]}]
I want to generate the following output:
result = ['2294162%238541851&ttgIds=S@', '2228013&ttgIds=B@']
I am close, but I am unable to extract and join the sport values correctly:
jmespath.search("[?not_null(@.leagues)].leagues[*].id.to_string(@) | [*].join(', ', @).join('', [[@],['&ttgIds=', '@']][]).replace(@, ', ', '%23')", data=data)
output = ['2294162%238541851&ttgIds=@', '2228013&ttgIds=@']
I tried using let
, but the output is empty:
jmespath.search("[?not_null(@.leagues)].leagues[*].let $sport_id = sport in id.to_string(@) | [*].join(', ', @).join('', [[@],['&ttgIds=', $sport_id, '@']][]).replace(@, ', ', '%23')", data=data)
output = [[], []]
Does anyone have an idea on how to solve this?