help with json data from the web into data frame in R
Hi! Seems to be an encoding problem. This worked for me (have not full- checked the output, though): fromJSON(encodeString(zWebObj)) HTH, Kimmo
2018-05-08 12:49 -0700, David Winsemius wrote:
On May 8, 2018, at 10:08 AM, Evans, Richard K. (GRC-H000) <richard.
k.evans at nasa.gov> wrote:
Hi David,??.. I think I've got it :-)?
Please let me know if you see anything glaringly wrong with this:
library(RCurl)
zWebObj <- postForm("https://www.semantic-mediawiki.org/w/api.php",
? "action" = "ask",
? "query" = "[[Category:City]]|?Capital%20of|?Has%20area",
? "format" = "json"
? .opts = list(ssl.verifypeer = FALSE)
)
The R interpreter tells me there's a missing comma after the line:?
"format" = "json"
Fixing that syntactic error I get:
str(zWebObj)
# ---bein console output
?atomic [1:1]
{"query":{"printrequests":[{"label":"","key":"","redi":"","typeid":"_
wpg","mode":2}],"results":{"File:2166320938 | __truncated__
?- attr(*, "Content-Type")= Named chr [1:2] "application/json" "utf-
8"
? ..- attr(*, "names")= chr [1:2] "" "charset"
#--- end console output-----
js1 <-fromJSON(zWebObj)
#--------
Error: lexical error: inside a string, '\' occurs before a character
which it may not.
??????????title":""}},"serializer":"SMW\Serializers\QueryResultSerial
i
?????????????????????(right here) ------^
I'm not really a JSON expert, so am not equipped to offer debugging
assistance there.
--?
David.
Thank you! -Rich -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Evans, Richard K. (GRC-H000) Sent: Tuesday, May 08, 2018 12:51 PM To: David Winsemius Cc: r-help at r-project.org Subject: Re: [R] help with json data from the web into data frame in R [non-tabular json data] -- ok.. so I think I need to figure out how to make it tabular. Thanks! [curl] -- I was hoping there was a cleaner way to do it.. using R to evoke cURL to get the data as text and then passing it into getJSON seems to be what I need to do. Do you by chance have an simple example of using RCurl to get a response ignoring cert errors? ty -Rich -----Original Message----- From: David Winsemius [mailto:dwinsemius at comcast.net]? Sent: Tuesday, May 08, 2018 12:25 PM To: Evans, Richard K. (GRC-H000) Cc: r-help at r-project.org Subject: Re: [R] help with json data from the web into data frame in R
On May 8, 2018, at 9:03 AM, Evans, Richard K. (GRC-H000) <richard .k.evans at nasa.gov> wrote: That said, I have two issues to ask for help with: 1) how to ignore cert errors with a fromJSON call
If you can do it with curl, then why aren't you doing one of a) a system call, b) installing and loading RCurl, c) installing and loading curl (the R package with that name)?
And? 2) why the json data from the example link doesn't convert to a data frame.
That was already answered in my earlier response. It's not a tabular result, so it doesn't "fit" into a tabular structure.