Hopefully this isn't a duplicate post. I have read through the numerous others regarding this kind of issue, but have had no success.
I want to parse the below JSON to Python, to print the current price of the stock. I have tried this using the below code:
from googlefinance import getQuotes
import json
stock = json.loads(getQuotes('AAPL'))
print(stock['LastTradePrice'])
However, this gives the below error...
I have tried also the below code:
from googlefinance import getQuotes
import json
print(json.dumps(getQuotes('AAPL'), indent=2))
Which successfully gives the following output
[
{
"Index": "NASDAQ",
"LastTradeWithCurrency": "129.09",
"LastTradeDateTime": "2015-03-02T16:04:29Z",
"LastTradePrice": "129.09",
"Yield": "1.46",
"LastTradeTime": "4:04PM EST",
"LastTradeDateTimeLong": "Mar 2, 4:04PM EST",
"Dividend": "0.47",
"StockSymbol": "AAPL",
"ID": "22144"
}
]
However, I just want to fetch the price from this and parse it through to a Python program. Why am I unable to do this? I have a feeling that it is because of the square brackets surrounding the json, but am unsure.

print(stock[0]['LastTradePrice'])? It is a list after all, with one element.qetQuotesdeals with thejsondeserializing already, and is returning a Python object. Why would youdumpsit?