Working on a little project and I may be in over my head. Using the CoinMarketCap API, I am trying to understand how to parse through their results to pull out just specific pieces of the returned value.
As an example:
result = {'status': {'timestamp': '2021-02-22T00:04:51.978Z', 'error_code': 0, 'error_message': None, 'elapsed': 46, 'credit_count': 1, 'notice': None}, 'data': {'1INCH': {'id': 8104, 'name': '1inch', 'symbol': '1INCH', 'slug': '1inch', 'cmc_rank': 83, 'last_updated': '2021-02-22T00:03:09.000Z', 'quote': {'BTC': {'price': 8.793673178965842e-05, 'volume_24h': 4010.9008604493424, 'percent_change_1h': 1.77689058, 'percent_change_24h': -3.76351861, 'percent_change_7d': -19.9798068, 'percent_change_30d': 66.4333541, 'market_cap': 12615.667000751586, 'last_updated': '2021-02-22T00:03:02.000Z'}}}}}
I am unable to figure out how to extract the 'symbol', 'cmc_rank', and 'market_cap' values from this variable. What is the proper approach to doing so?
Thank you
Try this solution, it should give you what you're looking for:
symbol = result['data']['1INCH']['symbol']
cmc_rank = result['data']['1INCH']['cmc_rank']
market_cap = result['data']['1INCH']['quote']['BTC']['market_cap']