Eric Eric - 9 months ago 38
JSON Question

Python, taking specific data from JSON

I'm playing around with the league of legends api, anyway I made this very simple program.

import requests
region = input("Enter a region ")
summonerName = input("Enter Summoner Name ")
apikey = input("Enter APIKey ")
r = requests.get(url="https://" + region + "" + region + "/v1.4/summoner/by-name/" + summonerName + "?api_key=" + apikey)

and this is what it returns.

{'hiimeric': {'revisionDate': 1478543641000, 'name': 'Hi Im Eric', 'id': 36843151, 'profileIconId': 13, 'summonerLevel': 30}}

so my question is now, how could I for example get it to only post 'name' or only 'name' and 'profileIconId'? Thanks!

Answer Source

A JSON object is actually just a combination of dictionaries and lists. Hence, you can print the name and profileIconId with the following: