I am trying to access a value from json by using jsonlite package, but the value (the value of key strongbuy where the period is 0m) I am trying to access has the same key name (period -1m has the same key name), so it returns NA value. Is there a way to do it with jsonlite or with regex?
i<- "MSFT"
json_object <- getURL(json_url)
quote_summary <- fromJSON(json_object) %>% unlist()
quote_summary["quoteSummary.result.recommendationTrend.trend.strongBuy"] %>% unname() %>% as.numeric()
Below is the value of json_object:
"{\"quoteSummary\":{\"result\":[{\"recommendationTrend\":{\"trend\":[{\"period\":\"0m\",\"strongBuy\":14,\"buy\":13,\"hold\":6,\"sell\":0,\"strongSell\":1},{\"period\":\"-1m\",\"strongBuy\":12,\"buy\":13,\"hold\":7,\"sell\":0,\"strongSell\":1},{\"period\":\"-2m\",\"strongBuy\":12,\"buy\":13,\"hold\":8,\"sell\":0,\"strongSell\":1},{\"period\":\"-3m\",\"strongBuy\":12,\"buy\":13,\"hold\":9,\"sell\":0,\"strongSell\":1}],\"maxAge\":86400}}],\"error\":null}}"
Below is the value of quote_summary:
quoteSummary.result.recommendationTrend.trend.period1
"0m"
quoteSummary.result.recommendationTrend.trend.period2
"-1m"
quoteSummary.result.recommendationTrend.trend.period3
"-2m"
quoteSummary.result.recommendationTrend.trend.period4
"-3m"
quoteSummary.result.recommendationTrend.trend.strongBuy1
"14"
quoteSummary.result.recommendationTrend.trend.strongBuy2
"12"
quoteSummary.result.recommendationTrend.trend.strongBuy3
"12"
quoteSummary.result.recommendationTrend.trend.strongBuy4
"12"
quoteSummary.result.recommendationTrend.trend.buy1
"13"
quoteSummary.result.recommendationTrend.trend.buy2
"13"
quoteSummary.result.recommendationTrend.trend.buy3
"13"
quoteSummary.result.recommendationTrend.trend.buy4
"13"
quoteSummary.result.recommendationTrend.trend.hold1
"6"
quoteSummary.result.recommendationTrend.trend.hold2
"7"
quoteSummary.result.recommendationTrend.trend.hold3
"8"
quoteSummary.result.recommendationTrend.trend.hold4
"9"
quoteSummary.result.recommendationTrend.trend.sell1
"0"
quoteSummary.result.recommendationTrend.trend.sell2
"0"
quoteSummary.result.recommendationTrend.trend.sell3
"0"
quoteSummary.result.recommendationTrend.trend.sell4
"0"
quoteSummary.result.recommendationTrend.trend.strongSell1
"1"
quoteSummary.result.recommendationTrend.trend.strongSell2
"1"
quoteSummary.result.recommendationTrend.trend.strongSell3
"1"
quoteSummary.result.recommendationTrend.trend.strongSell4
"1"
quoteSummary.result.recommendationTrend.maxAge
"86400"