Questions tagged [jsonlite]

A smarter JSON encoder and decoder

This package is a fork of RJSONIO by Duncan Temple Lang and builds on the same parser, but uses a different mapping between R objects and JSON data. More details can be found at http://cran.r-project.org/web/packages/jsonlite/index.html

A fast JSON parser and generator optimized for statistical data and the web. Started out as a fork of RJSONIO, but has been completely rewritten in recent versions. The package offers flexible, robust, high performance tools for working with JSON in R and is particularly powerful for building pipelines and interacting with web APIs.

The implementation is based on the mapping described in the vignette of the package (Ooms, 2014). In addition to drop-in replacements for toJSON and fromJSON, jsonlite contains functions to stream, validate, and prettify JSON data.

Reference manual: jsonlite.pdf Vignettes:

509 questions
3
votes
1 answer

Opencpu simple function json parsing not working

Hi I want to have a simple function for my local opencpu development server. getLinearInterpolatedEstimateQuantil <- function(x, type, probs){ result = quantile(data, type, probs) result #print for simpler debug } Example Debug input would be…
Georg Heiler
  • 16,916
  • 36
  • 162
  • 292
3
votes
1 answer

OpenCPU: No method asJSON S3 class

I am trying to get the JSON representation of the following resource: POST http://myserver/ocpu/library/stats/R/smooth.spline/json The error I get is No method asJSON S3 class: smooth.spline. The result of a smooth.spline() call has the following…
Maurizio
  • 547
  • 5
  • 13
3
votes
2 answers

Array in body for httr POST request

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"…
sckott
  • 5,755
  • 2
  • 26
  • 42
3
votes
1 answer

Trying to turn a data frame into hierarchical json array using jsonlite in r

I'm trying to get my super-simple data frame into something a little more useful - a json array in this case. My data looks like | V1 | V2 | V3 | V4 | V5 …
jrubins
  • 187
  • 13
3
votes
2 answers

OpenCPU and jsonlite: column-based "/json" versus row-based

Is there a clean way to change the default "/json" postfix option on data.frames to be column-based versus row-based? Data.frames in R, if I understand correctly, are really just named lists where each list is the same length as the others. Using…
r2evans
  • 141,215
  • 6
  • 77
  • 149
2
votes
1 answer

In R, convert list into stringified JSON for body of POST request

output_goal <- '{ "firstName": "Tim", "lastName": "Jones", "team": { "value":104290, "teamMarket": "Card", "gender": "MALE" }}' zed1 <- list(firstName = 'Tim', lastName = 'Jones', team = list(value = 104290, teamMarket = 'Card', gender =…
Canovice
  • 9,012
  • 22
  • 93
  • 211
2
votes
2 answers

Extract data.frame nested inside list

it is a basic command, but i cannot get around it. how can one extract/filter a data.frame inside a list which is inside a data.frame...? library(jsonlite) url <- "https://www.ine.pt/ine/json_indicador/pindica.jsp?op=2&varcd=0000611&lang=PT" data…
2
votes
0 answers

How can I get past this 'SSL connect error' when using jsonlite::fromJSON in R?

Issue I get the following error whenever I run all_companies <- jsonlite::fromJSON("https://www.sec.gov/files/company_tickers_exchange.json") Warning: URL 'https://www.sec.gov/files/company_tickers_exchange.json': status was 'SSL connect…
2
votes
1 answer

R: Encrypt string via cyphr, sending to JSON and then converting from JS back to string causes issue

I want to encrypt a string, and then format it to JSON, so I can send it to a database/the frontend safely. However, when retrieving encrypted data from the database, I need to go from JSON back to an R-string, which is an issue: key <-…
aleksandereiken
  • 430
  • 5
  • 9
2
votes
1 answer

R json obects with a single parameter value

I want to create the following json string {"water": {"amount": 0}} To do that I wrote the following code: df_water <- list(amount = 0) info <- list(water = df_water) %>% toJSON() But that results to: {"water": {"amount": [0]}} Any clues…
Diomides
  • 41
  • 2
2
votes
1 answer

USNO REST API in R

I am trying to extract moonrise and set times from the US Naval Observatory Rest API using the htrr and jsonlite packages. However, I keep getting an error saying, please supply dates in an MM/DD/YYYY format. Which I believe I am, so quite…
Patrick
  • 292
  • 1
  • 11
2
votes
1 answer

Importing nested JSON structure in R

I'm trying to import some data from an API that has an unusual nested JSON structure. Here's a snippet of what the JSON data looks like: {"series":[{"series_id":"NG.N9010US2.M","name":"U.S. Natural Gas Gross Withdrawals, Monthly","units":"Million…
Eric
  • 53
  • 1
  • 6
2
votes
0 answers

How to use jsonlite to import CMS dataset

I am trying to import a dataset from CMS using an API. My code, however, only returns 1,000 of the 155,262 observations. I don't know what I am doing wrong. Another user posted a similar problem, but regrettably, I still cannot it figure…
Mel G
  • 132
  • 1
  • 10
2
votes
1 answer

read write json with jsonlite in R

the task is to load a json, manipulate some data and write back. The first step is to just read and write the json file with identical out- and input, but this is not the case. Here a testfile which boils down the problem: { "hourly": [ { …
Nimrookie
  • 79
  • 3
2
votes
1 answer

convert tibble/dataframe to nested JSON with arrays

If got tons of tibbles with a structure like the following: library(tidyverse) library(jsonlite) data <- tibble(Type = c(rep("A", 10), rep("B", 5)), SubType = c(rep("a", 2), rep("b", 3), rep("c", 3), rep("d", 2), …
Rumpl
  • 333
  • 1
  • 11