rjson

How to send multiple documents using RMongo

限于喜欢 提交于 2019-12-13 16:11:53
问题 I am following the conventions from http://docs.mongodb.org/manual/reference/method/db.collection.insert/ to send a batch of multiple documents in one call of RMongo::dbInsertDocument. data=data.frame(A=c(1,2),B=c(3,4)) L=lapply(split(data,rownames(data)),as.list) names(L)=NULL dataJSON = toJSON(L) cat(dataJSON) which gives the following result: [ { "A":1, "B":3 }, { "A":2, "B":4 } ] Then dbInsertDocument(rmongo.object=myRmongo.object, collection=myCollection, doc=dataJSON) returns the

Processing JSON using rjson

折月煮酒 提交于 2019-12-13 14:17:32
问题 I'm trying to process some data in JSON format. rjson::fromJSON imports the data successfully and places it into a quite unwieldy list. library(rjson) y <- fromJSON(file="http://api.lmiforall.org.uk/api/v1/wf/predict/breakdown/region?soc=6145&minYear=2014&maxYear=2020") str(y) List of 3 $ soc : num 6145 $ breakdown : chr "region" $ predictedEmployment:List of 7 ..$ :List of 2 .. ..$ year : num 2014 .. ..$ breakdown:List of 12 .. .. ..$ :List of 3 .. .. .. ..$ code : num 1 .. .. .. ..$ name :

Problems reading JSON file in R

我的梦境 提交于 2019-12-12 13:44:46
问题 I have a JSON file (an export from mongoDB) that I'd like to load into R. The document is about 890 MB in size with roughly 63,000 rows of 12 fields. The fields are numeric, character and date. I'd like to end up with a 63000 x 12 data frame. lines <- readLines("fb2013.json") result: jFile has all 63,000 elements in char class and all fields are lumped into one field. Each file looks something like this: "{ \"_id\" : \"10151271769737669\", \"comments_count\" : 36, \"created_at\" : { \"$date\"

How to replace “unexpected escaped character” in R

我怕爱的太早我们不能终老 提交于 2019-12-12 11:10:17
问题 When I try to parse JSON from the character object from a Facebook URL I got "Error in fromJSON(data) : unexpected escaped character '\o' at pos 130". Check this out: library(RCurl) library(rjson) data <- getURL("https://graph.facebook.com/search?q=multishow&type=post&limit=1500", cainfo="cacert.perm") fbData <- fromJSON(data) Error in fromJSON(data) : unexpected escaped character '\o' at pos 130 #with RSONIO also error > fbData <- fromJSON(data) Erro em fromJSON(content, handler, default

Reading unescaped backslashes in JSON into R

我们两清 提交于 2019-12-11 20:20:03
问题 I'm trying to read some data from the Facebook Graph API Explorer into R to do some text analysis. However, it looks like there are unescaped backslashes in the JSON feed, which is causing rjson to barf. The following is a minimal example of the kind of input that's causing problems. library(rjson) txt <- '{"data":[{"id":2, "value":"I want to \\"post\\" a picture\\video"}]}' fromJSON(txt) (Note that the double backslashes at \\" and \\video will convert to single backslashes after parsing,

How to get Nested value Rjson

前提是你 提交于 2019-12-11 12:26:44
问题 I have data look like structure(list(`_id` = c(2653L, 2729L, 2920L, 2921L, 2922L, 2923L ), name = c("RunningApplicationsProbe", "RunningApplicationsProbe", "RunningApplicationsProbe", "RunningApplicationsProbe", "RunningApplicationsProbe", "RunningApplicationsProbe"), timestamp = c(1404116791.097, 1404116803.554, 1404116805.61, 1404116814.795, 1404116830.116, 1404116868.244 ), value = c("{\"duration\":12.401,\"taskInfo\":{\"baseIntent\":{\"mAction\":\"android.intent.action.MAIN\",\

How to convert dictionary data in to dataframe from JSON file in R?

北战南征 提交于 2019-12-11 10:57:10
问题 I'm new to the R. And I want to read the JSON file and convert into tabular structure file. Can you please help me how to convert the following data into the tabular structure format. The data is in JSON file as follows: {"Physics":8,"Chemistry":7,"PhysicalEducation":6,"English":7,"Mathematics":7,"serial":47738} {"Physics":1,"Chemistry":1,"PhysicalEducation":1,"English":3,"Mathematics":2,"serial":85520} {"Physics":2,"Chemistry":1,"Biology":2,"English":4,"Mathematics":8,"serial":182318} {

How to pass a variable in url in fromJSON command

爷,独闯天下 提交于 2019-12-11 08:53:30
问题 I am trying to pass a variable in the url and flatten using jsonlite, but i am not able to pass variable pages using the loop. How do i loop using FromJSON? pages<- list() for(i in 1:20) { mydata <- fromJSON("https:www.example.com/page="+i+"&access_token=xyz", flatten = TRUE) } filings <-rbind.pages(pages) 回答1: What about this? pages<- list() for(i in 1:20) { mydata <- fromJSON(paste("https:www.example.com/page=", i, "&access_token=xyz", sep = "+"), flatten = TRUE) } filings <-rbind.pages

R - Error in fromJSON(raw.data) : incomplete list

故事扮演 提交于 2019-12-08 12:57:52
问题 I'm trying to read API data from the BLS into R. I am using the Version 1.0 that does not require registration and is open for public use. Here is my code: url <-"http://api.bls.gov/publicAPI/v1/timeseries/data/LAUCN040010000000005" raw.data <- readLines(url, warn = F) library(rjson) rd <- fromJSON(raw.data) And here is the error message I receive: Error in fromJSON(raw.data) : incomplete list If I just try to go to the url in my webrowser it seems to work (pull up a JSON webpage). Not really

Converting a matrix/dataframe in R to JSON object with some constraints

梦想的初衷 提交于 2019-12-08 08:52:29
问题 REDITED: I have to convert a matrix in R to a JSON object with some structure in it. I am using the rjson package. Through an example, let me illustrate what I want. My specific case is the output of a recommender system code in R where the X2 X3 are the 2 closest items to a particular item X1. Also, X4,X5 are the scores of similarity associated with (X1,X2) and (X1,X3) for that row. I want all the recommended items for every item as JSON objects and every item along with its recommended JSON