Skip to content
Advertisement

how to decoding JSON file in python and get specific key

import requests
r = requests.get('test.com')
x=r.json()
print(x)

output is

{"test1":858,"test1":154343,"test":106091}

but x’s type is str, how to get key,value from x ? i want to get only 858

Advertisement

Answer

You can use the built-in json module:

import requests
import json

r = requests.get('test.com')
x = r.json()

print(json.loads(x)['test1'])

Output:

858
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement