felix felix - 5 months ago 7
JSON Question

Get value for only one JSON variable

I want to get the value for

with Python, using
requests
and
json
. I have this:

import requests
import json

res = requests.get('https://www.bitstamp.net/api/v2/ticker/btcusd/')
print res.json['last']


But it showed me this:

TypeError: 'instancemethod' object has no attribute '__getitem__'


It's working to get all JSON code with
res.json()
but I want only the value from
'last'
.

Answer

res.json() will parse the responses json object, which you need to do, to access any value of it. So to access the value last, you need to do: res.json()['last']