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

constructing json in R with jsonlite - too many brackets

Not a json expert, but I need what I think is referred to as "nested objects" and I am getting instead what I think is referred to as "nested arrays". In other words, some extra brackets. I'm trying to convert a dataframe into json data using…
bikeactuary
  • 447
  • 4
  • 18
2
votes
1 answer

Extract key-value pairs from tibble json column and unnest them into different rows

I have a tibble with JSON column that looks like: df <- tibble( id = c(1, 2), json_col = c('{"a": [1,2,3], "b": [4, 5, 6]}', '{"f": [100,2,8]}') ) I would like to get long format tibble that looks like: id | key | val ---------------- 1 | "a"…
mihagazvoda
  • 1,057
  • 13
  • 23
2
votes
2 answers

How to fix "invalid char in json text" when passing a URL via function to dplyr:mutate

I have written a function to retrieve data via API. The output format is JSON. https://jsoneditoronline.org/?id=ac0ec7ececae49ca92599ff912458a84 With every query a variable (path) should change. This variable is located in a dataframe…
Olaf Pleines
  • 41
  • 1
  • 7
2
votes
1 answer

Trying to get data from an API

I'm trying to get some appointment data from a practice management software. I have an API key but I have no experience in the area. I have tried to convert Curl code with little success. The api documentation is here…
2
votes
2 answers

How do I flatten a large, complex, deeply nested JSON file into multiple CSV files a linking identifier

I have a complex JSON file (~8GB) containing publically available data for businesses. We have decided to split the files up into multiple CSV files (or tabs in a .xlsx), so clients can easily consume the data. These files will be linked by the NZBN…
2
votes
1 answer

Convert JSON string to JSON object using R

How to convert that to a json object in R package jsonlite? the problem is I want to use an R function that expects a JSON object as argument. And I find myself doing toJSON(fromJSON(jsonStr)) every time I want to pass a JSON string just to change…
M.AbdAllah
  • 25
  • 5
2
votes
1 answer

How to deal with nested empty JSON arrays with tidyjson in R

I am reading a JSON object from Salesforce. The object is irregular in the sense that some nested arrays are empty and some are not. How to deal with this in tidyjson? I am setting up an API with Salesforce in R. The objective is to get meaningful…
Paul van Oppen
  • 1,443
  • 1
  • 9
  • 18
2
votes
0 answers

stream_in only specific columns/json elements?

I have a 9GB JSON file, and importing all of it requires an obscene amount of memory. To circumvent that, I'm want to read in only the JSON attributes I'm interested in. Right now, I'm running json_file <- stream_in(file("D:/Shodan/data.json")) Is…
JsDart
  • 183
  • 13
2
votes
0 answers

R: Extracting json data from an OData API gives inconsistent results?

I'm attempting to extract data from the Wales government statistics services OData API. Details on the API can be found here, including an example of how to filter the data. However I seem to be getting a non-deterministic subset of the data i.e.…
maja zaloznik
  • 660
  • 9
  • 24
2
votes
2 answers

Export JSON data frame in R formatting

I'm having some trouble formatting data my R data frame or table to the JSON file I want. This is the format I would like to have. { "PercentileFromR": [ "499 to 516", "517 to 534", "535 to 552", "553 to 569", "570 to 586", "587 to 604", "605 to…
adrienne
  • 103
  • 1
  • 9
2
votes
3 answers

JSON array in "body" parameter of httr::POST()

I want to send a post request with a few variables in the body, using the httr package. What the body would look like if it was in JSON format: {a:"1", b:"2", c:[{d:"3", e:"4"}]} What I tried with httr::POST() r <- POST("http://httpbin.org/post",…
jerome
  • 91
  • 7
2
votes
1 answer

Converting nested JSON to data frame

I am trying to convert a heavily nested json into a proper data frame (proper by tidy standards). An MWE of the json is copied at the end of the question, as I wanted to make sure it captured every element of the json. I've…
Adam_G
  • 7,337
  • 20
  • 86
  • 148
2
votes
1 answer

json array in httr post

I am trying to pass a json array in a POST request using the httr package. However I get a HTTP/1.1 400 Bad Request because of the formatting of the array. Here's how I build the request: decos <- list(name="ais-static-journey") decos <-…
Dhiraj
  • 1,650
  • 1
  • 18
  • 44
2
votes
2 answers

R: jsonlite package - fromJSON converts json files to character rather than intended list

Given this example data frame I can easily convert the nested json files into a flattened list, which I can then in subsequent steps convert into a dataframe with one column per json entry: sample.df.a <- data.frame(json_col =…
pd441
  • 2,644
  • 9
  • 30
  • 41
2
votes
1 answer

Embed nested list of data.frames in R

Setup: I have a tibble (named data) with an embedded list of data.frames. df1 <- data.frame(name = c("columnName1","columnName2","columnName3"), value = c("yes", 1L, 0L), stringsAsFactors = F) df2 <-…
Rhymenoceros
  • 119
  • 1
  • 8