Skip to content

Instantly share code, notes, and snippets.

@jfreels
Created October 9, 2013 16:53
Show Gist options
  • Save jfreels/6904461 to your computer and use it in GitHub Desktop.
Save jfreels/6904461 to your computer and use it in GitHub Desktop.
Convert R data.frame to JSON.
require(RJSONIO)
require(plyr)
json<-function(data.frame,sink=FALSE) {
modified<-list(
keys = colnames(data.frame),
values = unname(alply(data.frame,1,identity))
)
if(sink!=FALSE) {
sink(sink)
cat(toJSON(modified,pretty=TRUE))
sink()
}
if(sink==FALSE) {
cat(toJSON(modified,pretty=TRUE))
}
}
@Sirish6484
Copy link

Can you expand this code, i mean how does it print your dataframe??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment