jsonlite

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

▼魔方 西西 提交于 2019-11-30 10:54:13
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 Match"},{"Property":"C2","Value":"Address Mismatch"}]', '[{"Property":"81","Value":"XYZ"},{"Property":"D1","Value":"Blah Blah"},{"Property":"Z2","Value":"Email Mismatch"}]') ) I want to extract, format and separate the raw JSON in column y into orderly columns, ideally with library(jsonlite) . Thanks in advance! Using jsonlite and the tidyverse: library(tidyverse) library(jsonlite) df %>% mutate(y

multiple JSON objects in fromJSON

左心房为你撑大大i 提交于 2019-11-30 09:52:19
问题 I'm trying to use fromJSON() to read in a .json file with multiple objects structured as follows: { "key11": value11, "key12": value12 } { "key11": value11, "key12": value12 } … If I manually add [...] brackets around the entire file, and , commas between the objects, then the following code works: json_file <- "file.json" json_data <- fromJSON(json_file,flatten=TRUE) But adding the brackets and commas is not feasible for what I'm actually trying to do (I did it on a sample file). I tried

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

心已入冬 提交于 2019-11-30 05:44:44
问题 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 feed this json chokes on the latter and requires the former. Any suggestions on how to get the former behavior from jsonlite (or another R json package)? 回答1: The auto_unbox argument does the trick with the jsonlite package: toJSON(list(op='abc'),auto

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

偶尔善良 提交于 2019-11-30 03:19:09
问题 I have a log file that look like this. I'm trying to parse the JSON in the Message column by: library(readr) library(jsonlite) df <- read_csv("log_file_from_above.csv") fromJSON(as.character(df$Message)) But, I'm hitting the following error: Error: parse error: trailing garbage "isEmailConfirmed": false } { "id": -1, "firstName": (right here) ------^ How can I get rid of the "trailing garbage"? 回答1: fromJSON() isn't "apply"ing against the character vector, it's trying to convert it all to a

Read Json file into a data.frame without nested lists

让人想犯罪 __ 提交于 2019-11-27 21:18:55
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 reads the file in as a data.frame, but leaves nested lists in some of the variables. Does Anyone have any tips in loading a JSON file to a data.frame when it reads in with nested lists. #*#*#*#*#*#*#*#*#*##*#*#*#*#*#*#*#*#*# HERE IS MY EXAMPLE #*#*#*#*#*#*#*#*#*##*#*#*#*#*#*#*#*#*# # loads the packages library("httr") library( "jsonlite") # downloads an

Read Json file into a data.frame without nested lists

孤街醉人 提交于 2019-11-26 23:03:37
问题 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 reads the file in as a data.frame, but leaves nested lists in some of the variables. Does Anyone have any tips in loading a JSON file to a data.frame when it reads in with nested lists. #*#*#*#*#*#*#*#*#*##*#*#*#*#*#*#*#*#*# HERE IS MY EXAMPLE #*#*#*#*#*

Error parsing JSON file with the jsonlite package

雨燕双飞 提交于 2019-11-26 09:28:33
问题 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 http://1usagov.measuredvoice.com/ and unzipped it using 7zip, then I used the following code in R: library(jsonlite) jsonData <- fromJSON(\"usagov_bitly_data2013-05-17-1368832207\") I\'m not sure why this error happens, I looked up in Google but there\'s no