Hi All
With regards to recent COVID 19 tracking I was trying to connect R Studio with the raw data JSON API for India. I am producing my code below and it works well. I wanted to export the raw data in csv and it is doing it's work however it is not picking up the variable names and all the variables gets named as V1/V2/V3 etc. Please help me on what am I missing in this piece of work.
library(httr)
library(jsonlite)
library(rlist)
library(dplyr)
library(data.table)
jsonResponse <-GET("https://api.covid19india.org/raw_data.json")
http_type(jsonResponse)
http_error(jsonResponse)
jsonResponseText <- content(jsonResponse, as = "text")
jsonResponseText
jsonResponseParsed <- content(jsonResponse, as="parsed")
jsonResponseParsed
fromJSON(jsonResponseText)
modJson<-jsonResponseParsed$raw_data
modJson
modJson%>% bind_rows %>% select(dateannounced, detectedcity, detecteddistrict, detectedstate, estimatedonsetdate, gender, nationality, patientnumber, statecode, statepatientnumber, statuschangedate, currentstatus)
list.select(modJson,dateannounced, detectedcity, detecteddistrict, detectedstate, estimatedonsetdate, gender, nationality, patientnumber, statecode, statepatientnumber, statuschangedate, currentstatus)
modJson<-jsonResponseParsed$raw_data
modJson
list.stack(modJson)
rawdata <- data.frame(matrix(unlist(modJson), nrow=27891, byrow=T),stringsAsFactors=FALSE)
write.csv(rawdata,'D:\Projects\mjs.csv', row.names = FALSE)
Any help would be much appreciated.