Hello,
I was hoping someone could share some code samples or point me to a library that would help me transform a sql.Rows (i.e. sql record set) into a JSON message. I am dealing with several legacy database structure, so I can’t change some of the queries. I need to be able to transform sql.Rows to the JSON format provided below. Thank you very much in advance for your help!
Database structure layout, order by User Id.
User Id, Name, Street, City, Zip, State, Email, Phone, Friend ID, Friend Name.
Records
0,"Peck Duran","Chapel Street","Orbin",”94999","Maine","pp...@bbb.com","+1 (859) 111-1111",0,"Hendricks Vaughan".
0,"Peck Duran","Chapel Street","Orbin",”94999","Maine","pp...@bbb.com","+1 (859) 111-1111",10," Yesenia Franks ".
0,"Peck Duran","Chapel Street","Orbin",”94999","Maine","pp...@bbb.com","+1 (859) 111-1111",13," Wilder Landry ".
2," Vilma Barrera","Bayview Place","Fleetmix",”94998","Washington","vvvvv@fff.com","+1 (884) 222-2222",3," Tisha Kline".
2," Vilma Barrera","Bayview Place","Fleetmix",”94998","Washington","vvvvv@fff.com","+1 (884) 222-2222",2," Mccarthy Moreno".
2," Vilma Barrera","Bayview Place","Fleetmix",”94998","Washington","vvvvv@fff.com","+1 (884) 222-2222",4," Neva Pennington".
You will notice the user record repeats as many time as it contains different friends.
Here is the JSON message format needed.
[
{
"id": 0,
"name": "Peck Duran",
"street": "Chapel Street",
"city": "Orbin",
"zip": "94999",
"state": "Maine",
"email": "pp...@bbb.com",
"phone": "+1 (859) 111-1111",
"friends": [
{
"id": 0,
"name": "Hendricks Vaughan"
},
{
"id": 10,
"name": "Yesenia Franks"
},
{
"id": 13,
"name": "Wilder Landry"
}
]
},
{
"id": 1,
"name": "Vilma Barrera",
"street": "Bayview Place",
"city": "Fleetmix",
"zip": "94999",
"state": "Washington",
"email": "vvvvv@fff.com",
"phone": "+1 (884) 222-2222",
"friends": [
{
"id": 3,
"name": "Tisha Kline"
},
{
"id": 2,
"name": "Mccarthy Moreno"
},
{
"id": 4,
"name": "Neva Pennington"
}
]
}]