1

Tried reading my JSON data(extracted from a zip file) into an R-object using following code:


myHistory <- fromJSON("Takeout/Location History/Location History.json")


But Upon execution, getting the following error:

Error: lexical error: invalid char in json text. Takeout/Location History/Locati (right here) ------^

actual error pic

Kindly help

Sample data of JSON File:

> {   "locations" : [ {
>     "timestampMs" : "1467382628714",
>     "latitudeE7" : 286423676,
>     "longitudeE7" : 773812320,
>     "accuracy" : 688,
>     "activity" : [ {
>       "timestampMs" : "1467382628569",
>       "activity" : [ {
>         "type" : "IN_VEHICLE",
>         "confidence" : 61
>       }, {
>         "type" : "UNKNOWN",
>         "confidence" : 20
>       }, {
>         "type" : "STILL",
>         "confidence" : 10
>       }, {
>         "type" : "ON_FOOT",
>         "confidence" : 5
>       }, {
>         "type" : "WALKING",
>         "confidence" : 5
>       }, {
>         "type" : "ON_BICYCLE",
>         "confidence" : 3
>       } ]
>     } ]   }
  • It would help if you could provide sample data that is contained in the .json files. – Taufi Apr 27 '21 at 13:39
  • Thanks @Taufi , have added sample data in the .json file – user15498563 Apr 28 '21 at 14:24
  • In your case it is suggested to include a `readLines()` in the statement, i.e. `myHistory <- fromJSON(readLines("Takeout/Location History/Location History.json"))`. Look at this question with the same problem: https://stackoverflow.com/questions/41000112/reading-a-json-file-in-r-lexical-error-invalid-char-in-json-text – Taufi Apr 28 '21 at 15:50
  • 1
    This worked! I finally got my data. Thanks a lot! – user15498563 Apr 29 '21 at 08:37
  • Glad it helped. – Taufi Apr 29 '21 at 08:42

0 Answers0