1

I have a 5 columns named id, name, salary. dept in postgres DB.

I am fetching all the values of the columns & storing into a json file. But the problem i am getting is i am not able to store the values w.r.t the keys that means column name are the keys. I want to store the values as column name as key.

I tried with:

curser.execute(select id,name,salary, dept from employee)
record = curser.fetchall()

Here record is in the form of list. i want something like this below:

    {
    "id":"1"
    "name":[{"first":"abc"},{"last":xyz}]
    likewise others
}
  but i am getting like:
    {
    1
    [{"first":"abc"},{"last":xyz}]

}

can someone see the problem. If anyth other clarification need then feel free to ask me.Thanks in advance

 {
        "guid": "9c36adc1-7fb5-4d5b-83b4-90356a46061a",
        "name": "Angela Barton",
        "is_active": true,
        "company": "Magnafone",
        "address": "178 Howard Place, Gulf, Washington, 702",
        "registered": "2009-11-07T08:53:22 +08:00",
        "latitude": 19.793713,
        "longitude": 86.513373,
        "tags": [
            "enim",
            "aliquip",
            "qui"
        ]
    }


But i need like:

    { 
details:{
        "guid": "9c36adc1-7fb5-4d5b-83b4-90356a46061a",
        "name": "Angela Barton",
        "is_active": true,
        "company": "Magnafone",
        "address": "178 Howard Place, Gulf, Washington, 702",
        "registered": "2009-11-07T08:53:22 +08:00",
        "latitude": 19.793713,
        "longitude": 86.513373}
        "tags": [
            "enim",
            "aliquip",
            "qui"
        ]
    }

Here details is the columns.
parker
  • 87
  • 1
  • 8
  • Have you tried the solution presented here: http://stackoverflow.com/questions/10560394/how-do-i-query-using-fields-inside-the-new-postgresql-json-datatype – Ross Nov 10 '15 at 10:55
  • 1
    Show the table definition – Clodoaldo Neto Nov 10 '15 at 11:02
  • Actualy i cant show the table definition. i am mapping with other work. But i can tell you that i need the column names(id,name,salary,dept) as a key in my json response – parker Nov 10 '15 at 11:05
  • Please see the question again. I did edit something. – parker Nov 10 '15 at 11:13

0 Answers0