Import JSON file from URL to R

I tried to import a JSON file into R for a while using both the rjson and RJSONIO package, but I cannot get it to work. One of the code options that I used:

json_file <- "http://toolserver.org/~emw/index.php?c=rawdata&m=get_traffic_data&p1=USA&project1=en&from=12/10/2007&to=4/1/2011" json_data <- fromJSON(paste(readLines(json_file), collapse="")) 

As a result, an error message appears:

 Error in fromJSON(paste(readLines(json_file), collapse = "")) : unexpected character '<' 

I think the problem is in the first line of code because json_file contains the source of the website and not the actual content. I tried getURL () and getURLContent (), but without any success. Any help would be greatly appreciated!

Edit: as Martin Morgan pointed out, the problem is with the URL, not the code!

+4
source share
1 answer
 library(rjson) fromJSON(readLines('http://toolserver.org/~emw/index.php?c=rawdata&m=get_traffic_data&p1=USA&project1=en&from=12/10/2007&to=4/1/2011')[1]) 

works for me with a warning

+4
source

All Articles