0

I have a small problem, i need to use data from a json file and i can't find how to create my table. i have installed the rjson package and i have down the following :

fichier <- readLines("C:/Users/Documents/sujet.json") 

L <-lapply(fichier,fromJSON) 

Final_table <- lapply(L, data.frame) 

But it doesn't worked. My file "sujet.json" is composed of different json that's why i did the first lapply, but i can't create a table from that list. if someone have an idea.

Jake Burkhead
  • 6,435
  • 2
  • 21
  • 32
  • 1
    please provide a reproducible example see http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – jdharrison Jun 26 '14 at 14:14
  • for exmample my json is {"c":"ry-3d4rl1ng","t":1403672405569 } {"c":"ry-3d4rl1ng","t":1403672462176} – user3779690 Jun 26 '14 at 14:26

1 Answers1

0

How about

library(rjson)
fichier <- c("{\"c\":\"ry-3d4rl1ng\",\"t\":1403672405569 }", 
    "{\"c\":\"ry-3d4rl1ng\",\"t\":1403672462176}")

Final_table <- do.call(rbind, lapply(lapply(v, fromJSON), data.frame))

which produces

#             c            t
# 1 ry-3d4rl1ng 1.403672e+12
# 2 ry-3d4rl1ng 1.403672e+12

we just add in a step to convert the lists to data.frames and the combine them all together with rbind.

MrFlick
  • 195,160
  • 17
  • 277
  • 295