jsonlite

Converting nested JSON to data frame

﹥>﹥吖頭↗ 提交于 2019-12-24 10:18:07
问题 I am trying to convert a heavily nested json into a proper data frame (proper by tidy standards). An MWE of the json is copied at the end of the question, as I wanted to make sure it captured every element of the json. I've tried: library(jsonlite) library(tidyverse) dat <- jsonlite::fromJSON('data_toy.json') %>% pluck(1) %>% imap_dfr(~mutate(.x, department = .y)) but this returns: Error: Columns `time_spent`, `school_breakdown`, `reason_for_taking_course`, `student_years`, `interest_before`

POST encripted request with JSON body on R

扶醉桌前 提交于 2019-12-24 00:46:33
问题 I am trying to use R to post an encrypted request to an API. Specifically the /v3/orders/ request. It requires the use of an API key and secret , as well as an increasing nonce . Using openssl , jsonlite and httr libraries: The body has to be JSON encoded: book<-"btc_eth" side<-"sell" major<-"0.1" price<-"100" type<-"limit" Payload<-toJSON(data.frame(book=book,side=side,major=major,price=price,type=type)) It also requires an authorization header constructed with an sha256 encrypted signature

Parse JSON with special 'undefined' value?

本秂侑毒 提交于 2019-12-23 06:37:46
问题 In addition to strings and numbers, valid JSON can contain special values null and false I need to parse JSON that also contains undefined , which is a valid javascript value, but not a valid JSON value Example library(jsonlite) # A string works "[{\"Sepal.Width\":\"3.5\"}]" %>% fromJSON # Sepal.Width # 3.5 # A number works "[{\"Sepal.Width\":3.5}]" %>% fromJSON # Sepal.Width # 3.5 # null works "[{\"Sepal.Width\": null}]" %>% fromJSON # Sepal.Width # NA # false works "[{\"Sepal.Width\": false

Unable to Access data from json object

丶灬走出姿态 提交于 2019-12-20 05:20:48
问题 I have stored json data structure in a dataframe with single column, named json_data in R so my json text is stored in this format row 1) { "results" : [ { "formatted_address" : "Sahibzada Ajit Singh Nagar, Punjab, India", "types" : [ "route" ], "location" :"lat"31.1471305,"lng" 75.34121789999999 }, ] row 2) { "results" : [ { "formatted_address" : "SAS Nagar, Chennai, India", "types" : [ "route 2" ], "location" :"lat"30.67249,"lng" 23.988672537 ,}] row 3) { "results" : [ { "formatted_address"

When using jsonlite in R, how do I specify that only some of the entries are to be treated as arrays?

有些话、适合烂在心里 提交于 2019-12-20 03:11:56
问题 I have the following code: # install.packages("jsonlite") require("jsonlite") x = list( test = "my_test", data = c(1, 2, 3) ) toJSON(x) This prints: {"test":["my_test"],"data":[1,2,3]} I was expecting: {"test":"my_test","data":[1,2,3]} I've tried using some of the parameters from the documentation, but can't seem to get it right. 回答1: The argument auto_unbox=TRUE did the trick: automatically unbox all atomic vectors of length 1. It is usually safer to avoid this and instead use the unbox

Importing JSON into R with in-line quotation marks

天大地大妈咪最大 提交于 2019-12-19 04:01:39
问题 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 fails: library(jsonlite) fromJSON(readLines('~/my_file.json')) receiving an error: "Error in parseJSON(txt) : lexical error: invalid char in json text. 84","comment":"They call me "Bruce""}] (right here) ------^" Here is the output from R escaping of the file: readLines('~/my_file.json') "[{\"id

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

烈酒焚心 提交于 2019-12-18 13:48:08
问题 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) .

Extracting data from nested json document using tidyjson in R

二次信任 提交于 2019-12-12 19:19:51
问题 I am querying a research publication database. Articles have different number of authors (ranging from 1 to more than 20). My goal is to create an edge list of co-authors for social network analysis using iGraph. Below is a snippet of json { "format": "linked-data-api", "version": "0.2", "result": { "_about": "http://network.csiro.au:9500/standalone/publications.json?_pageSize=5&_page=1", "definition": "http://network.csiro.au:9500/standalone/meta/publications.json", "extendedMetadataVersion"

How to send json response using plumber R

南笙酒味 提交于 2019-12-12 19:16:32
问题 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 \"code\": \"200\",\n \"output\": {\n \"studentid\": \"1001\",\n \"name\": \"Kevin\"\n }\n}" ] Please help me format this json properly My Code #* @post /sum addTwo <- function(){ library(jsonlite) x <- list(status = "SUCCESS", code = "200",output = list(studentid = "1001",

Error while trying to parse json into R

六月ゝ 毕业季﹏ 提交于 2019-12-12 03:31:49
问题 I have recently started using R and have a task regarding parsing json in R to get a non-json format. For this, i am using the "fromJSON()" function. I have tried to parse json as a text file. It runs successfully when i do it with just a single row entry. But when I try it with multiple row entries, i get the following error: fromJSON("D:/Eclairs/Printing/test3.txt") Error in feed_push_parser(readBin(con, raw(), n), reset = TRUE) : lexical error: invalid char in json text. [{'CategoryType':