[R] Reading Json data

Mark Sharp msharp at txbiomed.org
Tue Jul 28 00:16:38 CEST 2015


Mayukh,

I think you are missing an argument to paste() and a right parenthesis character.

Try 
json_data <- fromJSON(paste(readLines(json_file), collapse = " "))

Mark
R. Mark Sharp, Ph.D.
msharp at TxBiomed.org





> On Jul 27, 2015, at 3:41 PM, Mayukh Dass <mayukh.dass at gmail.com> wrote:
> 
> Hello,
> 
> I am trying to read a set of json files containing tweets using the
> following code:
> 
> json_data <- fromJSON(paste(readLines(json_file))
> 
> Unfortunately, it only reads the first record on the file. For example, in
> the file below, it only reads the first record starting with "id":"tag:
> search.twitter.com,2005:3318539389". What is the best way to retrieve these
> records? I have 20 such json files with varying number of tweets in it.
> Thank you in advance.
> 
> Best,
> Mayukh
> 
> {"id":"tag:search.twitter.com
> ,2005:3318539389","objectType":"activity","actor":{"objectType":"person","id":"id:
> twitter.com:2859421","link":"http://www.twitter.com/meetjenn","displayName":"Jenn","postedTime":"2007-01-29T17:06:00.000Z","image":"06-19-07_2010.jpg","summary":"I
> say 'like' a lot. I fall down a lot. I walk into everything. Love Pgh Pens,
> NE Pats, Fundraising, Dogs & History. Craft Beer & Running
> Novice.","links":[{"href":"http://meetjenn.tumblr.com","rel":"me"}],"friendsCount":0,"followersCount":0,"listedCount":0,"statusesCount":0,"twitterTimeZone":"Eastern
> Time (US &
> Canada)","verified":false,"utcOffset":"0","preferredUsername":"meetjenn","languages":["en"],"location":{"objectType":"place","displayName":"Pgh/Philajersey"},"favoritesCount":0},"verb":"post","postedTime":"2009-08-15T00:00:12.000Z","generator":{"displayName":"tweetdeck","link":"
> http://twitter.com
> "},"provider":{"objectType":"service","displayName":"Twitter","link":"
> http://www.twitter.com"},"link":"
> http://twitter.com/meetjenn/statuses/3318539389","body":"Cool story about
> the man who created the @Starbucks logo. Additional link at the bottom on
> how it came to be:  http://bit.ly/16bOJk
> ","object":{"objectType":"note","id":"object:search.twitter.com,2005:3318539389","summary":"Cool
> story about the man who created the @Starbucks logo. Additional link at the
> bottom on how it came to be:  http://bit.ly/16bOJk","link":"
> http://twitter.com/meetjenn/statuses/3318539389
> ","postedTime":"2009-08-15T00:00:12.000Z"},"twitter_entities":{"urls":[{"expanded_url":null,"indices":[111,131],"url":"
> http://bit.ly/16bOJk
> "}],"hashtags":[],"user_mentions":[{"id":null,"name":null,"indices":[41,51],"screen_name":"@Starbucks","id_str":null}]},"retweetCount":0,"gnip":{"matching_rules":[{"value":"Starbucks","tag":null}]}}
> {"id":"tag:search.twitter.com
> ,2005:3318543260","objectType":"activity","actor":{"objectType":"person","id":"id:
> twitter.com:61595468","link":"http://www.twitter.com/FastestFood","displayName":"FastFood
> Bob","postedTime":"2009-01-30T20:51:10.000Z","image":"","summary":"Just A
> little food for
> thought","links":[{"href":"http://www.TeamSantilli.com","rel":"me"}],"friendsCount":0,"followersCount":0,"listedCount":0,"statusesCount":0,"twitterTimeZone":"Pacific
> Time (US &
> Canada)","verified":false,"utcOffset":"0","preferredUsername":"FastestFood","languages":["en"],"location":{"objectType":"place","displayName":"eating
> some
> thoughts"},"favoritesCount":0},"verb":"post","postedTime":"2009-08-15T00:00:23.000Z","generator":{"displayName":"oauth:17","link":"
> http://twitter.com
> "},"provider":{"objectType":"service","displayName":"Twitter","link":"
> http://www.twitter.com"},"link":"
> http://twitter.com/FastestFood/statuses/3318543260","body":"Oregon Biz
> Report » How Starbucks saved millions. Oregon closures ...
> http://u.mavrev.com/02bdj","object":{"objectType":"note","id":"object:
> search.twitter.com,2005:3318543260","summary":"Oregon Biz Report » How
> Starbucks saved millions. Oregon closures ... http://u.mavrev.com/02bdj
> ","link":"http://twitter.com/FastestFood/statuses/3318543260
> ","postedTime":"2009-08-15T00:00:23.000Z"},"twitter_entities":{"urls":[{"expanded_url":null,"indices":[70,95],"url":"
> http://u.mavrev.com/02bdj
> "}],"hashtags":[],"user_mentions":[]},"retweetCount":0,"gnip":{"matching_rules":[{"value":"Starbucks","tag":null}]}}
> {"info":{"message":"Replay Request
> Completed","sent":"2015-02-18T00:05:15+00:00","activity_count":2}}
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list