jsonlite

Ignore error when importing JSON files in R

若如初见. 提交于 2021-01-29 11:39:22
问题 I have this for loop that download a json file from a solr search server. It loops over a vector that contain keywords (100, in this case): library(jsonlite) for (i in 1:100) { docs <- fromJSON(paste("http://myurl.com/solr/select?df=topic&fq=",keywords[i],"&indent=on&q=*:*&rows=1&wt=json",sep="")) numFound <- docs$response$numFound print(numFound) } It works fine, until it reaches a certain keyword that is not found on the solr, and returns this error: Error in open.connection(con, "rb") :

How to unpack this jsonlite return value in R?

不想你离开。 提交于 2020-04-16 02:51:09
问题 I have this code: library(jsonlite) df <- fromJSON('blarg.json') from this json (in a file called blarg.json ): [{ "id": 211, "sub_question_skus": { "0": 329, "behavior": 216 } }, { "id": 333, "sub_question_skus": [ 340, 341 ] }, { "id": 345, "sub_question_skus": [ 346, 352 ] }, { "id": 444, "sub_question_skus": null }] That produces a data frame like so: > df id sub_question_skus 1 211 329, 216 2 333 340, 341 3 345 346, 352 4 444 NULL Ah, but look, its structure is quite complicated in the

Trouble using jsonlite's fromJSON() with URL in R

孤街浪徒 提交于 2020-03-03 10:50:13
问题 I have a URL that displays content (file IDs) from a certain website's API, in JSON format. To do this programmatically, I use the fromJSON(txt) function of the jsonlite package, which then parses the JSON into a vector (or list, not sure). This works perfectly on my home computer. However, when I run the same identical code at work, it seems that the fromJSON(txt) doesn't identify the URL as such and rather tries to parse the actual URL text, since I get the following error: Error: lexical

R: Vector of JSONs to data.frame

痞子三分冷 提交于 2020-03-02 08:02:28
问题 I have a vector of JSONs (of the same structure) and transform it to a data.frame. Following example does exactly what I want. require(jsonlite) # fromJSON() require(magrittr) # for the pipeline only require(data.table) # rbindlist() jsons <- c('{"num":1,"char":"a","list":{"x":1,"y":2}}', '{"num":2,"char":"b","list":{"x":1,"y":2}}', '{"num":3,"char":"c","list":{"x":1,"y":2}}') df <- jsons %>% lapply(fromJSON) %>% lapply(as.data.frame.list, stringsAsFactors = F) %>% rbindlist(fill = T) Some

lexical error: invalid bytes in UTF8 string

笑着哭i 提交于 2020-02-26 02:50:43
问题 I am trying to use the code shown below to extract data from a json file. However, the following error is returned: Error: lexical error: invalid bytes in UTF8 string. fr":"Ces données sont publiées avec un délai de cinq jours (right here) ------^ Inspecting the json file in my browser shows that the data appears as such: "fr":"Ces donn\u00e9es sont publi�es avec un d\u00e9lai de cinq jours." Is there a way to write the data while ignoring any UTF8 strings that cause an error? library

lexical error: invalid bytes in UTF8 string

回眸只為那壹抹淺笑 提交于 2020-02-26 02:50:13
问题 I am trying to use the code shown below to extract data from a json file. However, the following error is returned: Error: lexical error: invalid bytes in UTF8 string. fr":"Ces données sont publiées avec un délai de cinq jours (right here) ------^ Inspecting the json file in my browser shows that the data appears as such: "fr":"Ces donn\u00e9es sont publi�es avec un d\u00e9lai de cinq jours." Is there a way to write the data while ignoring any UTF8 strings that cause an error? library

jsonlite suddenly retunring error: “Failure when receiving data from the peer”

独自空忆成欢 提交于 2020-01-24 01:50:15
问题 Suddenly, over the weekend, my code is no longer working. when I run it, I receive the following message: Error in parse_con(txt, bigint_as_char) : Failure when receiving data from the peer the code is the following: raiz <- "https://olinda.bcb.gov.br/olinda/servico/Expectativas/versao/v1/odata/" tipo <- "ExpectativaMercadoMensais?%24format=json&%24select=" indicador <- "Indicador,Data,DataReferencia,Mediana,numeroRespondentes" restricao <- "&%24orderby=Data%20desc&%24filter=Indicador%20eq%20