jsonlite

R httr POST of JSON returns status 400

妖精的绣舞 提交于 2019-12-06 10:17:22
问题 I'm working on a few functions to get data from StatBank Denmark, and their API. They have made a console to test JSON calls and I know the basic_request I parse to JSON in the function dst_get_data works, as I have tested it in the console. I get a "status 400" error and an error message that says that I should "supply object when posting". The code below should make reproducible example. It is the third function (dst_get_data) where I am stuck. dst_meta <- function(table, ..., lang = "en"){

encoding a JSON expression from R with jsonlite or something else

邮差的信 提交于 2019-12-06 05:33:47
The API I'm using needs me to send it a JSON message like: y <- '[{"a":1, "b":"select", "c":["A", "B", "C"]}, {"a":2, "b":"text"}, {"a":3, "b":"select", "c":["D", "E", "F", "G"]}]' Notice that in the case "b" : "select" there is another variable c with the value being an array. When I try running fromJSON(y) (in the jsonlite package) I get a data.frame where the 3rd column is a list: > z <- fromJSON(y) > class(z) [1] "data.frame" > z %>% glimpse() Observations: 3 Variables: 3 $ a (int) 1, 2, 3 $ b (chr) "select", "text", "select" $ c (list) A, B, C, NULL, D, E, F, G But when I convert it back

JSON (using jsonlite) parsing error in R

会有一股神秘感。 提交于 2019-12-05 18:15:27
I have the following JSON file: {"id":1140854908,"name":"'Amran"} {"id":1140852651,"name":"'Asir"} {"id":1140855190,"name":"'Eua"} {"id":1140851307,"name":"A Coruna"} {"id":1140854170,"name":"A`Ana"} I used the package jsonlite but I get a parsing error library(jsonlite) try <- fromJSON("states.txt",simplifyDataFrame = T) # Error in feed_push_parser(readBin(con, raw(), n), reset = TRUE) : # parse error: trailing garbage # :1140854908,"name":"'Amran"} {"id":1140852651,"name":"'Asir" # (right here) ------^ Try changing your data file to below [ {"id":1140854908,"name":"'Amran"} ,{"id":1140852651

R httr POST of JSON returns status 400

霸气de小男生 提交于 2019-12-04 18:08:49
I'm working on a few functions to get data from StatBank Denmark, and their API . They have made a console to test JSON calls and I know the basic_request I parse to JSON in the function dst_get_data works, as I have tested it in the console. I get a "status 400" error and an error message that says that I should "supply object when posting". The code below should make reproducible example. It is the third function (dst_get_data) where I am stuck. dst_meta <- function(table, ..., lang = "en"){ require(jsonlite) require(httr) dkstat_url <- "http://api.statbank.dk/v1/tableinfo" params <- list(

reading a json file in R: lexical error: invalid char in json text

喜夏-厌秋 提交于 2019-12-04 16:26:47
问题 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

Array in body for httr POST request

混江龙づ霸主 提交于 2019-12-02 07:38:48
问题 This curl call works to create a new droplet on Digital Ocean curl -X POST "https://api.digitalocean.com/v2/droplets" \ -d '{"name":"test3","region":"nyc2","size":"512mb","image":5562742,"ssh_keys":[89103]}' \ -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" However, I'm having trouble getting an httr::POST() request to work only when the parameter ssh_keys is given. In the above method the ssh_keys parameter, if given, has to be an array. I assumed the list of parameters

R does not show special characters coming from json source

孤者浪人 提交于 2019-12-02 06:21:02
问题 a little bit about the background. I pull data from an API that supplies public transportation data. It returns the result in json format, which I process with the library 'jsonlite'. resp <- GET(url = url) resp_char <- rawToChar(resp$content) parsed <- fromJSON(resp_char, flatten = T) parsed.df <- do.call(what = "rbind", args = lapply(parsed[1], as.data.frame)) The problem is, in the result there are no special characters. I am working on a Windows Server 2012 machine and my language

Array in body for httr POST request

有些话、适合烂在心里 提交于 2019-12-02 03:48:19
This curl call works to create a new droplet on Digital Ocean curl -X POST "https://api.digitalocean.com/v2/droplets" \ -d '{"name":"test3","region":"nyc2","size":"512mb","image":5562742,"ssh_keys":[89103]}' \ -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" However, I'm having trouble getting an httr::POST() request to work only when the parameter ssh_keys is given. In the above method the ssh_keys parameter, if given, has to be an array. I assumed the list of parameters could be passed to the body as, e.g., where the ssh_keys parameter is inside a list args <- list(name=

Importing JSON into R with in-line quotation marks

只愿长相守 提交于 2019-11-30 23:23:01
I'm attempting to read the following JSON file ("my_file.json") into R, which contains the following: [{"id":"484","comment":"They call me "Bruce""}] using the jsonlite package (0.9.12), the following fails: library(jsonlite) fromJSON(readLines('~/my_file.json')) receiving an error: "Error in parseJSON(txt) : lexical error: invalid char in json text. 84","comment":"They call me "Bruce""}] (right here) ------^" Here is the output from R escaping of the file: readLines('~/my_file.json') "[{\"id\":\"484\",\"comment\":\"They call me \"Bruce\"\"}]" Removing the quotes around "Bruce" solves the

Parse Error: “Trailing Garbage” while trying to parse JSON column in data frame

时光怂恿深爱的人放手 提交于 2019-11-30 18:59:37
I have a log file that look like this . I'm trying to parse the JSON in the Message column by: library(readr) library(jsonlite) df <- read_csv("log_file_from_above.csv") fromJSON(as.character(df$Message)) But, I'm hitting the following error: Error: parse error: trailing garbage "isEmailConfirmed": false } { "id": -1, "firstName": (right here) ------^ How can I get rid of the "trailing garbage"? fromJSON() isn't "apply"ing against the character vector, it's trying to convert it all to a data frame. You can try purrr::map(df$Message, jsonlite::fromJSON) what @Abdou provided or jsonlite::stream