FAQ
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","ppppp@bbb.com","+1
(859) 111-1111",0,"Hendricks Vaughan".



0,"Peck Duran","Chapel Street","Orbin",”94999","Maine","ppppp@bbb.com","+1
(859) 111-1111",10," Yesenia Franks ".



0,"Peck Duran","Chapel Street","Orbin",”94999","Maine","ppppp@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": "ppppp@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"

             }

         ]

     }]

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Wes Freeman at Feb 23, 2014 at 5:17 am
    I just threw a quick and dirty example together with lib/pq...
    https://gist.github.com/wfreeman/9167240

    I just iterate over the rows and decide whether to add a new friend or add
    a new user (I called it message, not really sure why).

    Wes

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Marcio Dasilva at Feb 23, 2014 at 5:52 am
    Thank you very much, Wes!

    Cheers to you,
    Marcio
    On Friday, February 21, 2014 12:16:43 PM UTC-8, Marcio Dasilva wrote:

    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","ppppp@bbb.com","+1
    (859) 111-1111",0,"Hendricks Vaughan".



    0,"Peck Duran","Chapel Street","Orbin",”94999","Maine","ppppp@bbb.com","+1
    (859) 111-1111",10," Yesenia Franks ".



    0,"Peck Duran","Chapel Street","Orbin",”94999","Maine","ppppp@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": "ppppp@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"

    }

    ]

    }]
    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedFeb 23, '14 at 4:11a
activeFeb 23, '14 at 5:52a
posts3
users2
websitegolang.org

2 users in discussion

Marcio Dasilva: 2 posts Wes Freeman: 1 post

People

Translate

site design / logo © 2022 Grokbase