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
27
votes
9 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
23
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,660
  • 5
  • 26
  • 37
21
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
  • 9,874
  • 10
  • 54
  • 100
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
  • 235
  • 1
  • 2
  • 8
11
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,448
  • 2
  • 14
  • 32
9
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
  • 75,186
  • 15
  • 119
  • 225
9
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
  • 929
  • 12
  • 30
8
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,818
  • 4
  • 25
  • 52
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,543
  • 1
  • 25
  • 38
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
  • 317
  • 1
  • 10
7
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,219
  • 2
  • 11
  • 21
7
votes
2 answers

JSON (using jsonlite) parsing error in R

I have the following JSON file: {"id":1140854908,"name":"'Amran"} {"id":1140852651,"name":"'Asir"} {"id":1140855190,"name":"'Eua"} {"id":1140851307,"name":"A Coruna"} {"id":1140854170,"name":"A`Ana"} I used the package jsonlite but I get a…
user3006691
  • 435
  • 3
  • 7
  • 16
6
votes
1 answer

Nested R dataframe to JSON with objects instead of arrays

I need to convert a dataframe to JSON. There are several nested dataframes as variables in the dataframe to convert to JSON. But, when converting to JSON, I need the data for Values1 described below to be an object (enclosed in {} only) instead of…
Megan Beckett
  • 337
  • 1
  • 6
6
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,765
  • 20
  • 59
  • 74
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…
1
2 3
33 34