I would like to fetch data from a Reddit page but I'm having a problem converting into JSON with the RJSONIO package. It works for others Reddit pages but this one is causing me headache because it return invalid JSON input
.
library(RCurl)
library(RJSONIO)
json <- getURL("https://www.reddit.com/r/burstcoin/new.json?sort=rising?limit=100")
list <- RJSONIO::fromJSON(json)
Error in fromJSON(content, handler, default.size, depth, allowComments, :
invalid JSON input
> Encoding(json)
[1] "UTF-8"
I've try to remove non-ASCII characters with iconv
but it doesn't give the expected result and I still have the same error.
json <- iconv(json, "UTF-8", "ASCII", sub="")
> Encoding(json)
[1] "unknown"
I also use the stringi package which provides a function for general unicode conversion but still the same error.
library(stringi)
json <- stringi::stri_trans_general(json, "latin-ascii")
How can I parse this JSON file ?
Similar question : Removing non-ASCII characters from data files