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

Extract, format and separate JSON already stored in a data frame column

How might I parse and process JSON that already lives inside a data frame? Sample data: df <- data.frame( id = c("x1", "x2"), y = c('[{"Property":"94","Value":"Error"},{"Property":"C1","Value":"Found…
emehex
  • 9,874
  • 10
  • 54
  • 100
5
votes
2 answers

toJSON without outer square brackets

I am converting a nested list of a specific structure (required by an API) to JSON using toJSON() in jsonlite. However, I need the final JSON to not contain the outer square brackets (also required by an API). test_list <- list( list(formName =…
ztp
  • 97
  • 2
  • 9
5
votes
1 answer

How to use readLines in R to read all lines between a certain range?

I am trying to split a large JSONL(.gz) file into a number of .csv files. I have been able to use the code below to create a working .csv file, for the first 25.000 entries. I now want to read and parse the 25.001 to the 50.000th line, and have been…
Frank
  • 53
  • 1
  • 4
5
votes
3 answers

Removing brackets [] from ends of geojson in R

I'm trying to import a geojson into R as a spatial object (i.e., sp) from a USGS web service (streamstats) and am having trouble getting it into the right format for R. library(jsonlite) mydata <-…
Ryan
  • 178
  • 1
  • 9
5
votes
2 answers

How to send json response using plumber R

I need to send response from R using plumber package in below format { "status": "SUCCESS", "code": "200", "output": { "studentid": "1001", "name": "Kevin" } } But I am getting below format [ "{\n \"status\": \"SUCCESS\",\n …
5
votes
2 answers

How to merge data in to a pre-existing JSON structure in R?

First time poster, long time lurker. Be gentle. Moderate R user. I am sure there is a better, functional way to do what I need, but felt like I have researched do death with no insight. I am trying to merge a data set to a pre-existing JSON…
p0wd3rd
  • 53
  • 6
5
votes
1 answer

Converting a dataframe to nested json format

I am dealing with a r dataframe which looks like this below. id date items price 10 2014/09/13 shoes 187 10 2014/09/13 belt 35 10 2014/09/14 shirt 69 …
Kim Jenkins
  • 438
  • 3
  • 17
5
votes
1 answer

R - Serialize R models as JSON

Is there some good R package that can convert prediction models and other complex object to and from JSON? I have linear regression model from this example: eruption.lm = lm(eruptions ~ waiting, data=faithful) newdata =…
Jovan MSFT
  • 13,232
  • 4
  • 40
  • 55
5
votes
2 answers

Using jsonlite to write an unnamed list from R into a json array

I'm sending data to a C# developer who wants to use http://json2csharp.com/ to convert my data string into an array of objects. I thought that the jsonlite package would be good for this, but he's not getting the results he wants, and as I examine…
woodvi
  • 1,898
  • 21
  • 27
5
votes
1 answer

Import multiple json files from a directory and attaching the data

I am trying to read multiple json files into a working directory for further converting into a dataset. I have files text1, text2, text3 in the directory json. Here is the code i wrote: setwd("Users/Desktop/json") temp =…
user3570187
  • 1,743
  • 3
  • 17
  • 34
5
votes
1 answer

Importing JSON into R with in-line quotation marks

I'm attempting to read the following JSON file ("my_file.json") into R, which contains the following: [{"id":"484","comment":"They call me "Bruce""}] using the jsonlite package (0.9.12), the following…
WMC
  • 131
  • 1
  • 9
4
votes
1 answer

How do you convert R models to raw binary or string buffer?

I'm working in R 3.6 within a third-party environment (IBM Watson Studio) and need to be able to convert a model object into a raw binary or string buffer in order to save the model as indicated here. Briefly, I have to use a function that makes an…
ricniet
  • 115
  • 6
4
votes
2 answers

Authenticate using httr package when Making API Requests

I'm learning how to fetch data using an API in R. I understand that the aim of httr is to provide a wrapper for the curl package. The documentation I'm following so that I make requests to the API has the following HTTP request format. This code…
andy
  • 1,947
  • 5
  • 27
  • 46
4
votes
3 answers

How to read a newline delimited JSON file from R?

I have a newline delimited (i.e., each JSON object is confined to 1 line in the file): {"name": "json1"} {"name": "json2"} {"name": "json3"} In Python I can easily read it as follows (I must use the encoding encoding='cp850' to read my real…
Fluxy
  • 2,838
  • 6
  • 34
  • 63
4
votes
1 answer

How to parse a file with stacked multiple JSONs in R?

I have the following "stacked JSON" object within R, example1.json: {"ID":"12345","Timestamp":"20140101", "Usefulness":"Yes", "Code":[{"event1":"A","result":"1"},…]} {"ID":"1A35B","Timestamp":"20140102", "Usefulness":"No", …
ShanZhengYang
  • 16,511
  • 49
  • 132
  • 234
1
2
3
33 34