I'm using an API that returns a string formatted as a nested dictionary.
The problem is the structure of the string returns is very similar to a nested dictionary but it's not identically.
Below an example of what the API actually returns:
{
"quote":{
"symbol":"AMZN"
"companyName":"Amazon.com Inc."
"primaryExchange":"Nasdaq Global Select"
"sector":"Consumer Cyclical"
"calculationPrice":"close"
"open":3157.75
"openTime":1604064600266
"close":1739.65
"closeTime":1604088001623
"high":3167.004
"low":3019
"latestPrice":1739.65
"latestSource":"Close"
"latestTime":"October 30, 2020"
"latestUpdate":1604088001623
"latestVolume":NULL
"iexRealtimePrice":NULL
"iexRealtimeSize":NULL
"iexLastUpdated":NULL
"delayedPrice":3036.15
"delayedPriceTime":1604088001623
"extendedPrice":3044.2
"extendedChange":1304.55
"extendedChangePercent":0.74989
"extendedPriceTime":1604091597028
"previousClose":1724.42
"change":NULL
"changePercent":NULL
"iexMarketPercent":NULL
"iexVolume":NULL
"avgTotalVolume":3150697
"iexBidPrice":NULL
"iexBidSize":NULL
"iexAskPrice":NULL
"iexAskSize":NULL
"marketCap":860528336495
"peRatio":NULL
"week52High":3167.004
"week52Low":1307
"ytdChange":0.13911139273485668
}
"bids":[
]
"asks":[
]
"systemEvent":{
}
}
RAW text
{"quote":{"symbol":"AAPL","companyName":"Apple Inc.","primaryExchange":"Nasdaq Global Select","sector":"Technology","calculationPrice":"close","open":111,"openTime":1604064600921,"close":227.01,"closeTime":1604088000397,"high":111.99,"low":107.72,"latestPrice":227.01,"latestSource":"Close","latestTime":"October 30, 2020","latestUpdate":1604088000397,"latestVolume":null,"iexRealtimePrice":null,"iexRealtimeSize":null,"iexLastUpdated":null,"delayedPrice":108.86,"delayedPriceTime":1604088000397,"extendedPrice":109.05,"extendedChange":-117.96,"extendedChangePercent":-0.51962,"extendedPriceTime":1604091597895,"previousClose":220.82,"change":null,"changePercent":null,"iexMarketPercent":null,"iexVolume":null,"avgTotalVolume":28048177,"iexBidPrice":null,"iexBidSize":null,"iexAskPrice":null,"iexAskSize":null,"marketCap":1025899051800,"peRatio":null,"week52High":228.22,"week52Low":107.72,"ytdChange":0.48276164267212823},"bids":[],"asks":[],"systemEvent":{}}
As you can see, the quote dictionary is formatted as a normal dictionary, the problem is that the dictionaries bids
and asks
are empty and have square brackets.
I've tried this method Converting a string to a nested dictionary but it clearly doesn't work as my nested dictionary is not in a standard form
The final goal would be to extract the values from the dictionary as it's impossible at the moment with only a string.