I have a tough task, it is to download a json file from a format and re encode in other format to upload in a MongoDB. My json file is from Alpha Vantage (https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&apikey=demo) and has the following format.
"Time Series (1min)": {
"2018-07-13 16:00:00": {
"1. open": "105.4550",
"2. high": "105.5600",
"3. low": "105.3900",
"4. close": "105.4300",
"5. volume": "2484606"
},
"2018-07-13 15:59:00": {
"1. open": "105.5300",
"2. high": "105.5300",
"3. low": "105.4500",
"4. close": "105.4600",
"5. volume": "216617"
}
I need to re encode the file according the following schema using Day, hour and minute as keys.
{
'2018-07-13': {
'16': {
'00': {'open': 105.4550,
'high': 105.5600,
'low': 105.3900,
'close': 105.4300,
'volume': 2484606,}
}
}
'2018-07-13': {
'15': {
'59': {'open': 105.53000,
'high': 105.5300,
'low': 105.4500,
'close': 105.4600,
'volume': 6484606,}
}
}
}
I've done a lot of research but I didn't figure it out how to construct a Dictionary with multiple keys using a loop, at the same time I read the json file I'd like to re enconde in the Dict.