Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON to data frame in R

Tags:

json

r

jsonlite

I am trying to turn a .json file into a data frame for data visualization.

If I run the below code I get picture 1.

library(jsonlite)

jdata <- fromJSON("test.json")

data <- as.data.frame(jdata)

enter image description here

And when I try to transpose it, I get picture 2.

data2 <- as.data.frame(t(data))

enter image description here

This is how the json looks like raw:

enter image description here

I don't understand why column one has no name or is not part of the data frame (is jsonlite assuming these are tittles?). How can I overcome this?

I need a data frame from the json files:

Column1 (with the dates) | Column2 (I will divide it into values and coordinates

like image 221
Daniel Vargas Avatar asked Apr 10 '26 10:04

Daniel Vargas


1 Answers

Try this for the input file test.json

library(jsonlite)
jdata <- read_json("test.json", simplifyVector = TRUE)
like image 148
Prradep Avatar answered Apr 12 '26 02:04

Prradep



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!