I am trying to apply a match/case in my script where I want to do some action based on the JSON response from the API call:
response_types =
1. -> {'data': [{'id': 1485037059173588994}]}
2. -> {'data': [{'media': 1423364523411623943}]}
3. -> {'errors': [{'code': 404}]}
- I need to decide if it's
'data'or'errors' - After that if it's
'data', I need to decide if there is a key on position[0]of the list'id'-> [eg.if 'id' in r['data'][0]:]
or'media'-> [eg.if 'media' in r['data'][0]:]
Using
match-caseis pretty straightforward here:Note: using a throwaway wildcard
*_is necessary to ensure that thecasematchesdatakey lists of lengths>=1.