I have used this answer to convert json to dataframe but it seems that I can't implement it to my data.
I have download the files from here. As the title mentions they are json fies. I want to read them, make them dataframe and after that process save them to csv format.
Because the files are too big I have an experimental snippet of data here in the JavaScript field I use this json as an in.json files in the following code.
What is strange for me is this when I type nrow(df) I take back only 2 rows and when I save it to csv format I can see many columns which is wrong. Based on the id I have to have more than 2 rows. Could you help me what am I doing wrong please?
Here is the code I have
require(RJSONIO)
require(rjson)
library("rjson")
filename2 <- "C:/Users/Desktop/in.json"
json_data <- fromJSON(file = filename2)
json_data <- lapply(json_data, function(x) {
x[sapply(x, is.null)] <- NA
unlist(x)
})
json <- do.call("rbind", json_data)
df=json
df1 = df[df$state != "live",]
df1$projects.deadline <- as.POSIXct(df1$projects.deadline, origin="1970-01-01")
df1$projects.state_changed_at <- as.POSIXct(df1$projects.state_changed_at, origin="1970-01-01")
df1$projects.created_at <- as.POSIXct(df1$projects.created_at, origin="1970-01-01")
df1$projects.launched_at <- as.POSIXct(df1$projects.launched_at, origin="1970-01-01")
df2 = df1[,c("projects.id","projects.name","projects.blurb","projects.goal","projects.pledged","projects.state","projects.slug","projects.country","projects.currency","projects.currency_trailing_code","projects.deadline","projects.state_changed_at","projects.created_at","projects.launched_at","projects.backers_count","projects.creator.name","projects.location.id","projects.location.short_name","projects.location.displayable_name","projects.location.country","projects.category.id","projects.category.name","projects.id.1","projects.location.urls.api.nearby_projects.1","projects.category.id.1")]
df3 = df2[!duplicated(df2), ]
write.csv(df3,file='C:/Users/Desktop/final.csv', row.names=FALSE)
Please could you help me what is wrong in the previous steps?