www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Manipulate and parse jasonb object in timescaledb(postgresql)

reply Alain De Vos <devosalain ymail.com> writes:
When I read a record out of the database I receive a jsonb 
datatatype as a string.
How do I convert this string into a json object and parse and 
manipulate it?
Jul 14
next sibling parent reply Alain De Vos <devosalain ymail.com> writes:
With good select operators i can extract the data i need for 
instance:

select measurement->'room.temperature' from mytable;

Now how to process that further as json object ? or jsonb object 
in dlang ?
Jul 14
parent reply jfondren <julian.fondren gmail.com> writes:
On Wednesday, 14 July 2021 at 21:56:11 UTC, Alain De Vos wrote:
 With good select operators i can extract the data i need for 
 instance:

 select measurement->'room.temperature' from mytable;

 Now how to process that further as json object ? or jsonb 
 object in dlang ?
You'll need to either lean on postgres's support for jsonb querying to avoid having to pull a jsonb string into D, or you'll have to write a jsonb library. I don't see one in dub, and it's a bit hard to search for C libraries for it that you might interface easily with (or even where the type is defined. Is it a postgres invention?)
Jul 14
parent reply Alain De Vos <devosalain ymail.com> writes:
As an example i show this.
https://docs.python.org/3/library/json.html
But that is more what i look for.
Jul 14
parent jfondren <julian.fondren gmail.com> writes:
On Thursday, 15 July 2021 at 01:08:28 UTC, Alain De Vos wrote:
 As an example i show this.
 https://docs.python.org/3/library/json.html
 But that is more what i look for.
That's JSON, not JSONB. D has JSON support in https://dlang.org/phobos/std_json.html
Jul 14
prev sibling parent Steven Schveighoffer <schveiguy gmail.com> writes:
On 7/14/21 9:00 AM, Alain De Vos wrote:
 When I read a record out of the database I receive a jsonb datatatype as 
 a string.
 How do I convert this string into a json object and parse and manipulate 
 it?
Isn't jsonb just a storage assumption for the database (so it can do efficient indexing/searches)? When you get the data back, I would think it's just json data you can parse. I don't have experience with it, but I can't imagine a portable psql library that actually implements whatever binary storage format is being used inside the DB. -Steve
Jul 15