Using python to access a specific value in JSON
3 hours ago, Coaxialgamer said:I'm attempting to design a small program that returns a specific value from an API. The API returns as a json file with all the values it provides however , there are a multitude of elements in that json , and i only need one ( 'round_duration') .
I've installed the python requests library .
I'm fairly new to python and programming in general, and i don't have much of a clue as how to do this , especially considering this is a nonstandard library ( although a fairly popular one ).
My base code looks like this :
import requests url = '<sample url>' a=requests.get(url) print (a.text)When i execute this scrypt, i get all the data in the json . However , i only need round_duration . I've looked online but i can't seem to find a clear answer to this
Can anyone help with this?
json = JSON.loads(a.text)
print(json['round-duration'])
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now