Reading json file in R: lexical error: invalid char in json text

Here is an example of the code I'm using:

library(jsonlite) library(curl) #url url = "http://www.zillow.com/search/GetResults.htm?spt=homes&status=001000&lt=000000&ht=010000&pr=999999,10000001&mp=3779,37788&bd=0%2C&ba=0%2C&sf=,&lot=0%2C&yr=,1800&singlestory=0&hoa=0%2C&pho=0&pets=0&parking=0&laundry=0&income-restricted=0&pnd=0&red=0&zso=0&days=36m&ds=all&pmf=0&pf=0&sch=100111&zoom=6&rect=-91307373,29367814,-84759521,35554574&p=1&sort=globalrelevanceex&search=maplist&rid=4&rt=2&listright=true&isMapSearch=true&zoom=6" #json results_data_json = fromJSON(txt = url) 

Previously, I could run the same code with it without any problems. Now I get the following error:

 Error in feed_push_parser(buf) : lexical error: invalid char in json text. <html><head><title>Zillow: Real (right here) ------^ 

Any ideas around this?

+6
source share
3 answers

Like: R 3.2.2: "rjson" and "RJSONIO" package, but error using "fromJSON"

Installing the package alone is not enough. You need to load the library too ... Use the library (rjson) or the library (RJSONIO) or ... depending on which package you prefer, before calling any functions in it.

0
source

This happened to me by reading in json from a file. The code worked one day, and then the next day I received this error. In the end, I was able to get around the error, although I do not understand why my solution works. Firstly, I found a github post that suggested adding the readLines () function. For instance.

 r_object <- fromJSON(readLines("file.json")) 

When I did this, json booted correctly, but I received the following warning:

 Warning message: In readLines("file.json") : incomplete final line found on 'file.json'. 

Then, for some specific reason, I tried to add an extra line at the bottom of the JSON. Just an empty line after the last curly brace. And that fixed it. I do not know why. If anyone knows why this worked, write a comment.

0
source

I cannot repeat the mistake.

 class(results_data_json) [1] "list" 

My session info:

 R version 3.3.2 (2016-10-31) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7600) locale: [1] LC_COLLATE=Spanish_Colombia.1252 LC_CTYPE=Spanish_Colombia.1252 LC_MONETARY=Spanish_Colombia.1252 [4] LC_NUMERIC=C LC_TIME=Spanish_Colombia.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] curl_2.4 jsonlite_1.1 loaded via a namespace (and not attached): [1] tools_3.3.2 
-one
source

Source: https://habr.com/ru/post/1012951/


All Articles