0

I would like to read a json file where the sutructure is like below. I tried fromJson but it just read the first block. Can you help me on specify the delimiter to read all the file?

Thank you so much

json_data <- fromJSON(paste(readLines("C:C:/Users/aa/Data-test.json"), collapse=""))

Warning message: In readLines("C:/Users/aa/Data-test.json") : incomplete final line found on 'C:/Users/jsalim/Desktop/Docapost_20160718/FILES/Extract-Morgane_1307/Data-device2.json'

{
  "id" : "aaa",
  "dateModification" : "2016-06-04T04:29:30Z",
  "active" : true,
.....
}
{
  "id" : "bbbb",
  "dateModification" : "2016-06-04T04:29:30Z",
  "active" : true,
.....
}
{
  "id" : "ccc",
  "dateModification" : "2016-06-04T04:29:30Z",
  "active" : true,
.....
}
FallAndLearn
  • 4,035
  • 1
  • 18
  • 24
  • I don't have the datas line per line but block per block, when a block ended a new one start to the next line but readline is n't ablkle to find an EOL – Jasma Salim Jul 22 '16 at 08:17
  • `?jsonlite::stream_in` – hrbrmstr Jul 22 '16 at 11:59
  • When I try using stream_in it doexn't work , I also get the error opening file input connection. Error: parse error: premature EOF { (right here) ------^ closing file input connection. – Jasma Salim Jul 28 '16 at 14:57
  • if we had real test data someone wld prbly post a helpful working example. if you looked at `stream_in()` you'd see that i requires each streaming json record to be on a single line. possibly might have to use `jq` (the cmdline util) or `jqr` then (perhap in combo w/`jsonlite`) – hrbrmstr Jul 28 '16 at 16:15

1 Answers1

0

I believe that as in the answer suggested in this question, you just need to enter a carriage return at the end of the line (that is, there should be a single empty line at the end of your file). This worked for me in the same scenario.

Community
  • 1
  • 1
Serenthia
  • 1,222
  • 4
  • 22
  • 40