Re: JSON result parsing

2016-07-30 Thread Ben Bacarisse
TUA writes: > Calls to my REST api may either return a dict (for single results) or > a list of dicts (for multiple results). I think John's answer missed this part. > I receive these results using the requests library. > > I want to retrieve the value for a key 'ID' but only if I have a > sing

Re: JSON result parsing

2016-07-29 Thread John Gordon
In TUA writes: > I want to retrieve the value for a key 'ID' but only if I have a single > result and, obviously, if ID is present. > How can I do this with pythonic elegance? > Thanks for all suggestions! if len(results) == 1 and 'ID' in results: return results['ID'] else: