1

I have a file formatted in *.jsonl format, which I am trying to read in R and convert each of its objects to json. A reproducible data stored in the "filename.jsonl" is provided below.

{"lens_id":"049-046-612-457-696","jurisdiction":"US"}
{"lens_id":"011-002-622-427-296","jurisdiction":"US"}
{"lens_id":"0149-0416-6112-4527-6926","jurisdiction":"US"}

I am using the following R code:

library(jsonlite)
data="filename.jsonl"
content<-readLines(data)
fromJSON(content[1])

The problem that I am getting to is precisely related to reading the very first object of the data (i.e. content[1] in the code above). The error that I am getting is:

Error: lexical error: invalid char in json text.
{"lens_id":"049-046-612-4
(right here) ------^

Note that this error message does not occur when reading the second or third lines from the "filename.jsonl" data. I will appreciate if someone could please help me resolve this issue as I was unable to find a resolution online. Thanks in advance.

Dave
  • 329
  • 2
  • 10
  • I just found this resource related to BOM signature that can get added in front of a Json file, which one can remove by formatting in Notepad++. Here is link to the resource: https://stackoverflow.com/questions/2475113/weird-character-at-start-of-json-content-type – Dave Apr 27 '22 at 17:44

0 Answers0