JSON to CSV (getting only first row from the JSON file)

I have a JSON file. I would like to convert this JSON file into CSV. I have gone through several posts in the R Studio Community (here and here) and Stack Overflow. After reading them, I wrote a code.

My code is working only for the first row. This means, I am getting only 1st row from the JSON file. But, my JSON file containing 1024 rows. I check the file through the online website and received 1024 rows.

Compound <- fromJSON(file = "~/Compound.json")
df <- data.frame(t(sapply(Compound,c)))

Could you tell me, why I am getting only 1 row or how can I solve these issues?

Hi, I never did get to the bottom of this. Just looking at the other post you mention, looks like there is some sensible stuff in there.

Would like to know if this is possible.

Good luck!

Andrew

Update,

I solved the problem using jsonlite lite package. Because, my JASON was "ndjson" (newline-delimited json). Received help from StackOverflow here and here

install.packages("jsonlite")
library(jsonlite)

json <- stream_in(file("~/Food.json"), simplifyDataFrame=FALSE)
df <- data.frame(t(sapply(json,c)))

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

@andrewjmdata check my update comment. Solved the problem.