1

I am trying to import json file into R. For the purpose I am using packages such as rjson, jsonlite, RJSONIO, etc. I have tried different things as shown below but I got errors with all of them.

mydata <- fromJSON(paste(readLines("result_prod_14-15_08_17.json"), collapse=""))

The error I got is:

Error: lexical error: invalid char in json text.
                         {  "_id" : ObjectId("59920f495401ac79452a0
                 (right here) ------^

Using 'RJSONIO' package:

md <- stream_in(file("result_prod_14-15_08_17.json"))

produces the following error:

opening fileconnectionoldClass input connection.
Error: parse error: premature EOF
                                       {
                     (right here) ------^
closing fileconnectionoldClass input connection.

It must be something straightforward but since I am new to R I struggle to figure it out.

lmo
  • 37,904
  • 9
  • 56
  • 69
Datmach
  • 41
  • 1
  • 2
  • The simple answer is that it's not valid JSON. How was the file generated; an export from a database? – SymbolixAU Aug 27 '17 at 11:48
  • Yes it is actually an export from MongoDB database – Datmach Aug 27 '17 at 12:05
  • Now that I am thinking brace enclosed {..} items must be part of a larger comma-separated collection which is not the case with my data but if that's the issue I am not sure how I can solve it. – Datmach Aug 27 '17 at 12:38
  • you can use `library(mongolite)` to query mongodb directly from `R` – SymbolixAU Aug 27 '17 at 21:38

0 Answers0