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
2
votes
1 answer

Create Json from list in R with brackets

I am trying to create a JSON string to send in a POST request from an API (CTUIT's swagger API for restaurants). # Load packages ---------------------------------------------- library(tidyverse) library(httr) library(jsonlite) I make a nested list…
Chris Kiniry
  • 499
  • 3
  • 13
2
votes
1 answer

Using GTmetrix REST API v2.0 in R

I am trying to integrate the performance testing of certain websites using GTmetrix. With the API, I am able to run the test and pull the results using the SEO connector tool in Microsoft Excel. However, it uses the xml with older version of API,…
Mohanasundaram
  • 2,889
  • 1
  • 8
  • 18
2
votes
1 answer

jsonlite array of arrays

when using jsonlite to import a json that has an array inside other array I get an undesired unnamed list. Exemple below: myjson=jsonlite::fromJSON('{ "class" : "human", "type" : [{ "shape":"thin", …
Fallen lord
  • 196
  • 1
  • 12
2
votes
1 answer

When using jsonlite in R, how to specify manually which are treated as arrays? The auto_unbox doesn't work in this case

I have the following code: data = list( "id" = equip_id, "initial_date" = 1608433200, "final_date" = 1609038000, "limit" = 10000, "order" = "asc", "properties" = "forecast" ) If I use: jsonlite::toJSON(data, auto_unbox =…
2
votes
0 answers

Transforming JSON into data frame in R

I am trying to transform a rather complicated and nested JSON file into a data frame using R. After trying a lot of different approaches I do not seem to get further with this. I feel like I just lack the knowledge of the right functions here. An…
jpquast
  • 333
  • 2
  • 8
2
votes
1 answer

Iterating through JSON elements to fix missing values using R and jsonlite

I'm working with a JSON file and trying to flatten it into a data.frame using the jsonlite package. The main set of objects in the array don't have a key, and so instead of flattening into rows, it's creating a column for each object (and its…
ezra
  • 23
  • 3
2
votes
0 answers

Is code injection possible in R via functions that read CSVs or parse JSON from the web?

Web frameworks that inadequately sanitise inputs can be prone to SQL injection. Are R processes vulnerable to 'R injection' in the same way? That is, can someone (or some API) provide inputs to R functions (especially those that can read from the…
stevec
  • 41,291
  • 27
  • 223
  • 311
2
votes
3 answers

Parse dictionary-like structure in which key and values are numeric values using R

I'm trying to parse some bizarre data structures I've encountered during my travels. Essentially they resemble python or javascript dictionaries, but both the key and the value are numeric: weird <- "{47=4578.0005, 181=23456.7831,…
Xavier GB
  • 97
  • 1
  • 7
2
votes
1 answer

Decoding base64 string in R gives unexpected binary output

I have this string: x <-…
antecessor
  • 2,688
  • 6
  • 29
  • 61
2
votes
1 answer

s3.save a json file to aws s3

I'm trying to save a correctly formatted json file to aws s3. I can save a regular data frame to s3 with e.g. library(tidyverse) library(aws.s3) s3save(mtcars, bucket = "s3://ourco-emr/", object = "tables/adhoc.db/mtcars/mtcars") But I need to get…
Doug Fir
  • 19,971
  • 47
  • 169
  • 299
2
votes
0 answers

Ensure that data frames become tibbles when reading MongoDB data with {mongolite}

I have to deal with JSON documents that contain nested documents and at some level have an array which in turn contains individual documents that conceptionally would map back to a "data frame row" when reading/parsing the JSON in R. How can I…
Rappster
  • 12,762
  • 7
  • 71
  • 120
2
votes
1 answer

Recursively ensuring tibbles instead of data frames when parsing/manipulating nested JSON

I have to deal with JSON documents that contain nested documents and at some level have an array which in turn contains individual documents that conceptionally would map back to "data frame rows" when reading/parsing the JSON in R. First order…
Rappster
  • 12,762
  • 7
  • 71
  • 120
2
votes
2 answers

Is there a way to extract multiple attributes efficiently from a JSON column?

I have a dataframe that has one column which contains json data. I want to extract some attributes from this json data into named columns of the data frame. Sample data json_col = c('{"name":"john"}','{"name":"doe","points": 10}', '{"name":"jane",…
Jerry Thomas
  • 305
  • 3
  • 7
2
votes
1 answer

How can I recognize null values as "NA" in my rbind function?

I'm using rbind as part of a function to write json data to a simple data frame in R. I've nearly successfully created my df, but rather than writing in NULL values as "NA" my r script prints the next available variable in the frame that should be…
JMK
  • 25
  • 4
2
votes
1 answer

How to remove or prevent escape slashes from json-file data in azure logic app workflow

Situation I'm using Azure Logic App to do the following steps: Load/read a JSON file from blob storage. This file is created and written in R, using the toJSON function fromt JSONlite package Get de file content from this JSON file Convert it to a…