0

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?

0

1 Answer 1

1

It sounds as if your data frame consists of two rows of lists. Try using the apply function to delist each row in your dataframe.

Sign up to request clarification or add additional context in comments.

2 Comments

Please could you give me an example?
Do you know what lists are?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.