Hi friends,

I was trying to read a MySQL table and then converting to data.frame to
JSON format. Following is the code

library(RJSONIO);
con <- dbConnect("MySQL", host="localhost", user ="root", dbname = "myDB")
rs1 <- dbGetQuery(con, "select * from strawhats;")
print(rs1)
json_rs <- toJSON(rs1);
print(json_rs)

But I get columns of the data.frame info in vector form as shown following.

> source("data.R")
  id           name  position                      ambition
1  1 Monkey D Luffy   Captain I Will become the pirate king
2  2   Roronoa zoro  Swordman       Become greatet swordman
3  3          Sanji      Cook                 Find all blue
4  4           Nami Navigator         Draw map of the world
5  5          Usopp    Sniper       Become greatest warrior

[1] "{\n \"id\": [ 1, 2, 3, 4, 5 ],\n\"name\": [ \"Monkey D Luffy\",
\"Roronoa zoro\", \"Sanji\", \"Nami\", \"Usopp\" ],\n\"position\": [
\"Captain\", \"Swordman\", \"Cook\", \"Navigator\", \"Sniper\"
],\n\"ambition\": [ \"I Will become the pirate king\", \"Become greatet
swordman\", \"Find all blue\", \"Draw map of the world\", \"Become greatest
warrior\" ] \n}"

Is there any easy way to get data.frame information in row form. I mean, in
the following format

{ { id : 1, name: "Monkey D Luffy", position: "captain", ambition: "I will
become the pirate king" } , {id: 2, name:"Roronoa zoro", position:
"swordman", ambition:"become greate swordman" } , { } , { }, { } }

Please let me know if there is any way to do this.

Regards,
MLSC

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to