Hi! I have collected 500.000+ tweets with a Python script using 'tweepy', which stored the data in JSON format. I would like to use R for data analysis, but have encountered problems when trying to import the data file with 'jsonlite'. Here what I have tried: > data.df<-fromJSON("example.json") Error in feed_push_parser(readBin(con, raw(), n), reset = TRUE) : parse error: trailing garbage stamp_ms":"1436705823768"} {"created_at":"Sun Jul 12 12:57 (right here) ------^ The import fails already on the first line :( A sample file causing this error is attached. I have tried several solutions, e.g. this: http://stackoverflow.com/questions/26519455/error-parsing-json-file-with-the-jsonlite-package but it does not work and results in the same error. Could anyone help me to understand what is causing the error and how to solve the issue? Thanks in advance. Kind regards, Kimmo Elo -- University of Turku, Finland Dep. of political science and contemporary history
On 23/10/2015 3:44 PM, K. Elo wrote:> Hi! > > I have collected 500.000+ tweets with a Python script using 'tweepy', > which stored the data in JSON format. I would like to use R for data > analysis, but have encountered problems when trying to import the data > file with 'jsonlite'. > > Here what I have tried: > > > data.df<-fromJSON("example.json") > Error in feed_push_parser(readBin(con, raw(), n), reset = TRUE) : > parse error: trailing garbage > stamp_ms":"1436705823768"} {"created_at":"Sun Jul 12 12:57 > (right here) ------^ > > The import fails already on the first line :( A sample file causing this > error is attached. > > I have tried several solutions, e.g. this: > http://stackoverflow.com/questions/26519455/error-parsing-json-file-with-the-jsonlite-package > > but it does not work and results in the same error. > > Could anyone help me to understand what is causing the error and how to > solve the issue? Thanks in advance.It looks like it's the same sort of problem as in that stackoverflow posting: what's in your file is not valid Javascript, so it's not valid JSON. It's probably multiple JSON objects without proper separators; you need to do the separating yourself. BTW, your attachment failed; only some file types are allowed. You should probably put the file online somewhere and post the URL. Duncan Murdoch
Hi! You can download the example file with this link: https://www.dropbox.com/s/tlf1gkym6d83log/example.json?dl=0 BTW, I have used a JSON validator and the problem seems to related to wrong/missing EOF. --- snip --- Error: Parse error on line 1: ...:"1436705823768"} {"created_at":"Sun J ---------------------^ Expecting 'EOF', '}', ',', ']', got '{' --- snip --- However, editing the file with a text editor to create "proper" EOF doesn't help. -Kimmo- 23.10.2015, 22:52, Duncan Murdoch wrote:> It looks like it's the same sort of problem as in that stackoverflow > posting: what's in your file is not valid Javascript, so it's not valid > JSON. It's probably multiple JSON objects without proper separators; > you need to do the separating yourself. > > BTW, your attachment failed; only some file types are allowed. You > should probably put the file online somewhere and post the URL. > > Duncan Murdoch