3

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

5
  • So, I got it to work with dplyr, but is there a way jsonlite can do this? Commented Jul 11, 2017 at 15:44
  • What does your json look like? If you look carefully you can see that in picture 1 the rows holding the timestamp doesn't have a name either Commented Jul 11, 2017 at 16:19
  • pictures aren't code or data unless image processing is the question. there are many examples of how to properly ask questions. Commented Jul 11, 2017 at 16:21
  • @derHugo the name of the whole file is "updates". I updated the question. Commented Jul 11, 2017 at 16:22
  • That's not a good formatted json than ... You don't have Variable names there but rather a different variable name for each update .... A better (and only usefull) way would look like {"updates":[ {"time":"2017....", "value":"hello,....." },...]} Commented Jul 11, 2017 at 16:27

1 Answer 1

4

Try this for the input file test.json

library(jsonlite)
jdata <- read_json("test.json", simplifyVector = TRUE)
Sign up to request clarification or add additional context in comments.

1 Comment

@Prrarep Thanks!

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.