user3006691 February 2016

JSON (using jsonlite) parsing error in R

I have the following JSON file:

{"id":1140854908,"name":"'Amran"} 
{"id":1140852651,"name":"'Asir"} 
{"id":1140855190,"name":"'Eua"} 
{"id":1140851307,"name":"A Coruna"} 
{"id":1140854170,"name":"A`Ana"}

I used the package jsonlite but I get a parsing error

library(jsonlite) 
try <- fromJSON("states.txt",simplifyDataFrame = T)
# Error in feed_push_parser(readBin(con, raw(), n), reset = TRUE) :   
# parse error: trailing garbage
#           :1140854908,"name":"'Amran"} {"id":1140852651,"name":"'Asir"
#                      (right here) ------^

Answers


vmachan February 2016

Try changing your data file to below

[
{"id":1140854908,"name":"'Amran"} 
,{"id":1140852651,"name":"'Asir"} 
,{"id":1140855190,"name":"'Eua"} 
,{"id":1140851307,"name":"A Coruna"} 
,{"id":1140854170,"name":"A`Ana"}
]

The same code worked for me.. It is looking for an array..

Post Status

Asked in February 2016
Viewed 3,165 times
Voted 12
Answered 1 times

Search




Leave an answer