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

Converting a JSON text field of unequal nesting depth to a dataframe

I am trying to convert a column in a data extract in to a data.frame Lets say in the table extract, I have a column extract$stage of type: character , the first 11 rows of which looks similar to the following extract <- read.table (text =…
Jon
  • 445
  • 3
  • 15
0
votes
0 answers

Error in extracting json content from an API request: Error: parse error: premature EOF?

I'm trying to retrive data from an API, the request I get back is of type "application/json", however when I try to extract the content as text I get an empty string and, therefore, also the fromJSON command fails. The following code worked until…
RNO
  • 1
0
votes
0 answers

fast extraction of json field in a dataframe

I have a large dataframe (250k rows) with one column being a json text. The json is large with multi elements. I would like to parse one or two elements of that json. I used jsonlite::fromJSON() but that seems inefficient because I would be parsing…
Courvoisier
  • 904
  • 12
  • 26
0
votes
1 answer

How do I deal with a nested list() that occurs when reading JSON files in R?

I have several JSON files that should be read and merged using r. Each file contains data for 51 observations. However, when I read the JSON file in r, the information I need is nested in the column "mentions". I need the time stamp that is…
pa_01
  • 11
  • 3
0
votes
0 answers

Nested JSON of Google API to table in R

Can you help me please, I am trying to convert the JSON that returns a google API to a tabular format (dataframe) to export to a CSV or other tabular type. I have attached a screenshot of the expected result I have seen several examples on the…
Erick
  • 1
0
votes
2 answers

r converted to json, need value null to be unquoted

I am sending a http request where the body needs to be in json format. As standard it seems that value null is being quoted. This prevents the http request to work properly. When testing to build a string manually and removing the quotes for value…
Toolbox
  • 2,333
  • 12
  • 26
0
votes
1 answer

Cannot deserialize instance with R POST()

I'm trying to get a queryID using the POST() funtion in R. It works well as long as I only use a simple JSON library(httr) library(jsonlite) base_json <- paste(' { "segment" : "WHG_M" } ') id <- POST("url", body =…
thmschk
  • 614
  • 3
  • 16
0
votes
2 answers

How can i Merge/Summaries two JSON array into one based on one key variable in R?

I have some JSON arrays as - "expenseRecords": [ { "date_expensed": "2019-04-01", "exp_cat_description": "Air Travel", "totalamountUSD": 10, "totalRecords": 2 }, { "date_expensed": "2019-04-01", …
0
votes
0 answers

How to convert JSON data into R

[ { "type": ["MixedExponential"], "mean": [16105.5], "sd": [44733.7177], "means": [2456, 545, 83553, 2432, 65546], "weights": [0.2, 0.4, 0.1, 0.2, 0.1] }, { "type": ["Normal"], "mean": [15000], "sd": [10000] …
0
votes
2 answers

extract nested dataframes from complex JSON efficiently using purrr functions and %>%

I'm trying to build a table similar to this (this is just a couple rows, but I'm trying to get all of the hits from a list of games): game_pk atBatIndex pitchNumber hardness launchAngle launchSpeed location totalDistance trajectory coordX…
Don Hessey
  • 67
  • 11
0
votes
0 answers

jsonlite: toJSON on object from Python's requests package leads to arrays, direct call to API does not

I'm playing around with some Fantasy Premier League data available through an API. Desired result, nested dataframes, is achieved when running the following code: library(jsonlite) url <-…
djfinnoy
  • 585
  • 3
  • 13
0
votes
2 answers

Using a wildcard to get all nodes

I'm trying to pull data from a json file using a wildcard. The data I'm trying to pull are the game stats for every player from this json file. They are under…
Don Hessey
  • 67
  • 11
0
votes
1 answer

how to quickly parse many small JSON files?

I have thousands of very small json files in a directory. Right now, I am using the following code to load them: library(dplyr) library(jsonlite) library(purrr) filelistjson <- list.files(DATA_DIRECTORY, full.names = TRUE, recursive =…
ℕʘʘḆḽḘ
  • 18,566
  • 34
  • 128
  • 235
0
votes
0 answers

Creating Attribute:Value Pairs in JSON Format

I am basically trying to replicate the following json structure with jsonlite (any other package like rson would also be fine if it works better). { "classes": [1, 2, 3], "ID": 0, "Name": "Peter", "Address": "" } My approach so far:…
vanao veneri
  • 970
  • 2
  • 12
  • 31
0
votes
1 answer

lexical error: invalid bytes in UTF8 string

I am trying to use the code shown below to extract data from a json file. However, the following error is returned: Error: lexical error: invalid bytes in UTF8 string. fr":"Ces données sont publiées avec un délai de cinq jours …
mouphasa
  • 1
  • 1
  • 1