Re: Getting the queried result in the form of json structure

From: Hector Vass <hector(dot)vass(at)metametrics(dot)co(dot)uk>
To: msn <pioneer(dot)suri(at)gmail(dot)com>, "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Getting the queried result in the form of json structure
Date: 2016-04-26 14:08:40
Message-ID: DB5PR0601MB2008C389C5CC5A21FABC1E7ABC630@DB5PR0601MB2008.eurprd06.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-sql

cast it

select info::text from sample;

________________________________________
From: pgsql-sql-owner(at)postgresql(dot)org <pgsql-sql-owner(at)postgresql(dot)org> on behalf of msn <pioneer(dot)suri(at)gmail(dot)com>
Sent: 26 April 2016 12:32
To: pgsql-sql(at)postgresql(dot)org
Subject: [SQL] Getting the queried result in the form of json structure

I am using postgresql for my webapplication. I am new to this
Postgresql-json. I Just want to get the select query result in the form of
json structure.
Here are my details:

Create table
============
- create table sample(id, serial, info jsonb);
Insert query
============
- insert into sample("info") values('{"person": {"phone":
9804484234,"name":{"firstname":"Alice", "lastname":"bob"}, "empId": "E067",
"age":25}');

select query:
=============
select "info"->'person'->>'lastname' from sample;

result: bob

but I want to get the above result along with the json nodes like below:

result: {"person":
{"name":
{"lastname":"bob"}
}
}

could any tell me how to get my expected result structure from database.

--
View this message in context: http://postgresql.nabble.com/Getting-the-queried-result-in-the-form-of-json-structure-tp5900554.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.

--
Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message msn 2016-04-29 09:40:44 Re: Getting the queried result in the form of json structure
Previous Message msn 2016-04-26 11:32:00 Getting the queried result in the form of json structure