Reputation: 345
Here is my code:
forbesList<-fromJSON('https://www.forbes.com/ajax/list/data?year=2018&uri=powerful-brands&type=organization')
Error Details:
Error in parse_con(txt, bigint_as_char) : lexical error: invalid char in json text. (!doctype html) (html lang="en") (right here) ------^
Please help me out, i tried in many ways to resolve this issue, but failed. Any help is much appreciated.
Upvotes: 1
Views: 2083
Reputation: 522084
The first parameter of fromJSON
needs to be actual JSON text, not a URL pointing to some JSON text. Try downloading the JSON content first, then make your call to fromJSON
:
library(httr)
url <- "https://www.forbes.com/ajax/list/data?year=2018&uri=powerful-brands&type=organization"
req <- GET(url)
stop_for_status(req)
json <- content(req, "text")
forbesList <- fromJSON(json)
I have verified here that the JSON content from your URL parses correctly, so I don't think this should be a problem.
Upvotes: 1