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

Passing Date parameters into REST API call - Using R-

Trying to pull some data from a REST API however unable to correctly pass as date parameter into the string. Using sprintf I was successful in passing in the search term and website however no luck with the discoverDate. https://newsriver.io is the…
mannym
  • 325
  • 1
  • 16
2
votes
2 answers

POST encripted request with JSON body on R

I am trying to use R to post an encrypted request to an API. Specifically the /v3/orders/ request. It requires the use of an API key and secret, as well as an increasing nonce. Using openssl, jsonlite and httr libraries: The body has to be JSON…
2
votes
1 answer

Parse JSON in R using key and value

I have a JSON URl - https://{{API_HOST}}/api/dd/new which needs to be parsed in R. It has a Key and Value, Through which I am easily able to parse the JSON in Postman by applying key and value in Headers section. Looking a way to do the same in R…
string
  • 787
  • 10
  • 39
2
votes
1 answer

Extracting data from nested json document using tidyjson in R

I am querying a research publication database. Articles have different number of authors (ranging from 1 to more than 20). My goal is to create an edge list of co-authors for social network analysis using iGraph. Below is a snippet of json…
aterhorst
  • 625
  • 4
  • 14
2
votes
1 answer

convert opensensors json file to data frame (or table)

A low cost air quality sensor (AQE) sends its data to the opensensors.io server. Every x seconds it sends a string of information (timestamp, pollutant concentration, etc). The data can be retrieved structured as a json file. Opensensors terminology…
JerryN
  • 2,356
  • 1
  • 15
  • 49
2
votes
0 answers

fromJSON encoding issue

I try to convert a json object to R dataframe, here is the json object: json <- '[ {"Name" : "a", "Age" : 32, "Occupation" : "凡达"}, {"Name" : "b", "Age" : 21, "Occupation" : "打蜡设计费"}, {"Name" : "c", "Age" : 20, "Occupation" : "的拉斯克奖飞"} ]' then…
rankthefirst
  • 1,370
  • 2
  • 14
  • 26
2
votes
0 answers

How to POST and retrieve data from a database in R using REST API?

I need to call an API within R which will make the request to a database server and fetch the results into an R dataframe. The API I have is of the form: http://servername01.home.local/tech-myobjectapi-0.3/myObjectApi/api/v2/Object I also have to…
j1897
  • 1,507
  • 5
  • 21
  • 41
2
votes
2 answers

R: Vector of JSONs to data.frame

I have a vector of JSONs (of the same structure) and transform it to a data.frame. Following example does exactly what I want. require(jsonlite) # fromJSON() require(magrittr) # for the pipeline only require(data.table) # rbindlist() jsons <-…
Jan Kislinger
  • 1,441
  • 14
  • 26
2
votes
1 answer

list conversion of jsonlite in R

I would like to have a list of matrices within R imported from a json file using jsonlite. A <- matrix(rnorm(100),10,10) B <- matrix(rnorm(100),10,10) C <- matrix(rnorm(100),10,10) l <- list(A,B,C) import_l <- fromJSON(toJSON(l),simplifyMatrix =…
math
  • 1,868
  • 4
  • 26
  • 60
2
votes
2 answers

Passing unquoted javascript to Highcharts using toJSON

Using shiny and rCharts to create a dashboard app, I need to pass raw javascript (not a string) to the Highcharts object. Given this list series <- list(data = list(c(0, 0), c(100, 0), c(100, 100)), type = 'polygon', …
2
votes
2 answers

Why jsonlite parses data into a list object ?

I try to parse data from a web API with jsonlite but for some reason the object it returns is a list. It is said in the jsonlite package documentation that simplification process will automatically convert JSON list into a more specific R class but…
Florent
  • 1,791
  • 22
  • 40
2
votes
1 answer

Collapse list of JSON with nested structures into single data.frame

I'm trying to parse some results from an API. The API returns a JSON result for a given value. The API can only handle one value at a time so I lapply to get all the results. <- If this is a bad start point happy to here a better way! Each JSON…
Steph Locke
  • 5,951
  • 4
  • 39
  • 77
2
votes
2 answers

encoding a JSON expression from R with jsonlite or something else

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…
wdkrnls
  • 4,548
  • 7
  • 36
  • 64
2
votes
2 answers

parse JSON containing embedded lists into flattened data.frame, ignoring unwanted key

A colleague is sending me an Elasticsearch query result (100000's of records, hundreds of attributes) that looks like: pets_json <-…
C8H10N4O2
  • 18,312
  • 8
  • 98
  • 134
2
votes
1 answer

The toJSON(fromJSON('1.json')) in rjsonlite does not produce the same JSON

I was trying to use jsonlite to work with my JSON requests. I was expecting that applying toJSON() to the result of fromJSON() and writing it to a file will produce the same JSON as the original. Apparently, fromJSON does a lot of type conversion…