Thread overview
Manipulate and parse jasonb object in timescaledb(postgresql)
Jul 14, 2021
Alain De Vos
Jul 14, 2021
Alain De Vos
Jul 14, 2021
jfondren
Jul 15, 2021
Alain De Vos
Jul 15, 2021
jfondren
July 14, 2021

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?

July 14, 2021

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 ?

July 14, 2021

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?)

July 15, 2021

As an example i show this.
https://docs.python.org/3/library/json.html
But that is more what i look for.

July 15, 2021

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

July 15, 2021

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