jsonb_object without loosing type information

Hello everyone,

I’m trying to create a JSONB object from two array (retrieved from a previous select). One is of type string[] (keys), the other is float[] (values). However jsonb_object required two text arrays.

How can I create a JSONB object given these circumstances, without loosing the float type information? In other words, how do I go from here: ["key1", "key2"] and [10, 5], to there: {"key1":10, "key2":5}?

Thank you in advance!

Hey @SebastianWilczek,

Unfortunately, for now, the JSONB object does not support type information.

I’m almost certain the types are converted to strings.

Here is an example to show how you can insert your JSON values to a table.

insert into <table(column)> values (jsonb_object(array['key1', 'key2']::string[], array[5, 10]::float[]::string[]));

if you are using a client driver, you can try implementing some logic there to retrieve your values in float format.

Here are some docs relating to JSONB.

Let me know if this was helpful.

Thanks,
Matt