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:

419 questions
20
votes
3 answers

Error parsing JSON file with the jsonlite package

I'm trying to read a JSON file into R but I got this error: Error in parseJSON(txt) : parse error: trailing garbage [ 33.816101, -117.979401 ] } { "a": "Mozilla\/4.0 (compatibl (right here) ------^ I downloaded the file from…
adolfohc
  • 225
  • 1
  • 2
  • 8
19
votes
4 answers

Read Json file into a data.frame without nested lists

I am trying to load a json file into a data.frame in r. I have had some luck with the fromJSON function in the jsonlite package - But am getting nested lists and am not sure how to flatten the input into a two dimensional data.frame. Jsonlite…
MatthewR
  • 2,399
  • 3
  • 20
  • 29
18
votes
1 answer

Parse Error: "Trailing Garbage" while trying to parse JSON column in data frame

I have a log file that look like this. This is a text document that looks like: Id,Date,Level,Message 35054,2016-06-17 19:29:43 +0000,INFO,"{ ""id"": -2, ""ipAddress"": ""100.100.100.100"", ""howYouHearAboutUs"": null, …
emehex
  • 7,082
  • 8
  • 46
  • 85
17
votes
3 answers

reading a json file in R: lexical error: invalid char in json text

Here is an example of the code I'm using: library(jsonlite) library(curl) #url url =…
user3083674
9
votes
2 answers

Successfully coercing paginated JSON object to R dataframe

I am trying to convert JSON pulled from an API into a data frame in R, so that I can use and analyze the data. #Install needed packages require(RJSONIO) require(httr) #request a list of companies currently fundraising using httr r <-…
verybadatthis
  • 1,228
  • 1
  • 12
  • 30
8
votes
1 answer

interfacing R to PostgreSQL 9.4 JSONB data type

With PostgreSQL 9.4 a new datatype JSONB has become available. According to the performance tests made available on a single node the performance is better than with mongodb (which understandably is not the sweet spot for mongodb). Is it possible…
Enzo
  • 2,421
  • 1
  • 22
  • 37
8
votes
2 answers

"NA" in JSON file translates to NA logical

I have json files with data for countries. One of the files has the following data: "[{\"count\":1,\"subject\":{\"name\":\"Namibia\",\"alpha2\":\"NA\"}}]" I have the following code convert the json into a data.frame using the jsonlite package: df =…
Armin
  • 307
  • 1
  • 9
7
votes
1 answer

How can I encode an R vector of length 1 as a single value in json using the jsonlite R package?

I am trying to encode R lists into json using the jsonlite package and the toJSON function. I have a simple item like: list(op='abc') I'd like that to become: { "op" : "abc" } Instead, I get: { "op" : ["abc"] } The API to which I am trying to…
seandavi
  • 2,667
  • 4
  • 21
  • 41
6
votes
1 answer

Warning jsonlite in shiny: Input to asJSON(keep_vec_names=TRUE) is a named vector

Consider this shiny app: library(shiny) library(ggplot2) ui <- fluidPage( radioButtons("type", "Type of plot", choices = c("density", "boxplot")), plotOutput("plot") ) server <- function(input, output){ output[["plot"]] <- renderPlot({ …
Stéphane Laurent
  • 48,421
  • 14
  • 86
  • 170
6
votes
1 answer

Create nested/hierarchical JSON with R and JSONLITE?

I am struggling to create a nested/hierarchical JSON file. In reality, my file will have varying numbers of children at different levels (from zero children to several), and each "node" in the tree will have the same key:value pairs: name, id, type.…
Tim
  • 739
  • 8
  • 26
6
votes
1 answer

How to construct a JSON with nested lists

I need to dynamically construct the following JSON. { "status": "SUCCESS", "code": "200", "output": { "studentid": "1001", "name": "Kevin" } } I tried it with the jsonlite package, but I can't construct the inner JSON object. Please…
Rajesh Kumar
  • 611
  • 6
  • 19
6
votes
1 answer

jsonlite for R gives error when trying to install

Where does one get jsonlite? Apparently it is missing from CRAN? > install.packages('jsonlite') Gives: Installing package into ‘C:/Users/cbusch/Documents/R/win-library/3.2’ (as ‘lib’ is unspecified) trying URL…
Chris
  • 1,094
  • 2
  • 10
  • 18
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 convert R dataframe to Json in name/value pair?

I have the following R data frame: Values Type1 123 Type2 4565 Type3 7812 I expect the JSON output to be {"Type1":123, "Type2":4565, "Type3":7812} The number field can w/wo quote I used jsonlite toJSON, the output…
BlueDolphin
  • 9,601
  • 18
  • 55
  • 72
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 …
Rajesh Kumar
  • 611
  • 6
  • 19
1
2 3
27 28