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

Add key and value to JSON in R

I used jsonlite library: json_pca_data <- toJSON(pca_table, pretty = TRUE)) to produce JSON: { "neuron_type" : [ "Ciliated_sensory_neurons", "Touch_receptor_neurons", ... ... ], "PC1" : [ 4.1158, …
Nikita Vlasenko
  • 4,004
  • 7
  • 47
  • 87
4
votes
0 answers

Jsonlite: Error: parse error: premature EOF

I am trying to read this data into R with Jsonlite: "{\"Transaction\":…
Soren
  • 53
  • 1
  • 4
4
votes
2 answers

R does not show special characters coming from json source

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) …
ahLoco
  • 111
  • 6
4
votes
1 answer

get wrong result by converting json string containing large number by using jsonlite

Here is the MWE, how to get the correct number as character. require(jsonlite) j <- "{\"id\": 323907258301939713}" a <- fromJSON(j) print(a$id, digits = 20) class(a$id) a$id <- as.character(a$id) a$id class(a$id) Here is the output. Loading…
Christophe
  • 195
  • 2
  • 9
4
votes
2 answers

How to load online JSON data to shiny app with jsonlite?

I am trying to make shiny app that takes data from this api: https://www.riigiteenused.ee/api/et/all. I need to use jsonlite::fromJSON, because it has good flatten function. When I use the following code (minimal example, in real life I do more…
Risto Hinno
  • 51
  • 2
  • 5
4
votes
3 answers

How to flatten nested data frames returned from jsonlite

I am loading this JSON data with jsonlite "rawData": { "fortune": {}, "plaintext": {}, "db": {}, "update": { "duda": [ { "latencyAvg": "201.40us", "latencyMax": "727.00us", …
Hamy
  • 20,662
  • 15
  • 74
  • 102
3
votes
1 answer

Write json scalars in R

In r, I have some data in a data frame and need to export it to jsonl. In jsonl each line is its own valid json. As the linked question shows, you can easily do that by applying jsonlite::toJSON() to each row. My problem is that I need one of the…
shs
  • 3,683
  • 1
  • 6
  • 34
3
votes
2 answers

R convert columns to JSON rowwise

I have data.frame df <- data.frame(a = c(1,3),b = c(2,4)) a b 1 1 2 2 3 NA and I want to receive a data.frame like this: a b json 1 1 2 {"a":1, "b":2} 2 3 NA {"a":3} I wonder if there is a way to get this result…
thmschk
  • 614
  • 3
  • 16
3
votes
3 answers

Parse multi-level json file in r

I have a pretty good understanding of R but am new to JSON file types and best practices for parsing. I'm having difficulties building a data frame from a raw JSON file. The JSON file (data below) is made up of repeated measure data that has…
Sescro
  • 33
  • 3
3
votes
1 answer

Not able to extract data from API using R

I have below mentioned dataframe in R: DF ID Code PO-1 123 PO-3 345 PO-4 222 I want to pass the ID in api get specific response from the JSON. I have the api like "https://test.com/path/code-info?ID=PO-1" with header…
Sophia Wilson
  • 581
  • 3
  • 16
3
votes
1 answer

R - Parsing JSON code with multiple levels

I'm trying to parse JSON using R. Using fromJSON() in the jsonlite package gets me most of the way there. But what's the most efficient way build out a data frame when the json has multiple levels? Say I have this json code: [ { …
waealu
  • 331
  • 1
  • 9
3
votes
0 answers

R language: Stream OUT to an URL

I'm trying to get some date from and endpoint and then send it to another endoint (with some modifications in the middle) My goal is to use Streams in both cases (in and out) This is kind of what i have: library(jsonlite) library(curl) hPOST <-…
oriuken
  • 653
  • 3
  • 7
  • 19
3
votes
1 answer

Add JSON column to R dataframe

I have a data frame and want to add an additional column that contains the data per row in JSON format. In this example: dfr = data.frame(name = c("Andrew", "Mathew", "Dany", "Philip", "John", "Bing", "Monica"), age = c(28, 23, 49, 29, 38, 23,…
StefanG
  • 1,234
  • 2
  • 22
  • 46
3
votes
2 answers

How to write this json object in Postgresql with R

I have this table CREATE TABLE example ( ID serial NOT NULL PRIMARY KEY, name varchar(1024), coords json ); And I want to write this json in this table: [ { "name": "first", "coords":{ "lat": 3.14, …
3
votes
1 answer

When using jsonlite in R, how do I specify that only some of the entries are to be treated as arrays?

I have the following code: # install.packages("jsonlite") require("jsonlite") x = list( test = "my_test", data = c(1, 2, 3) ) toJSON(x) This prints: {"test":["my_test"],"data":[1,2,3]} I was…
André C. Andersen
  • 8,955
  • 3
  • 53
  • 79
1 2
3
33 34