Create multi-key JSON object with integers or floats as values
Update

According to your sample data and desired result you can get it using json_object_agg Postgres function.




CREATE TABLE test (str text, num double precision);
INSERT INTO test(str, num) VALUES ('a', 1.0);
INSERT INTO test(str, num) VALUES ('b', 2.3);






select json_object_agg(str, num)
from test;



| json_object_agg        |
| :--------------------- |
| { &quot;a&quot; : 1, &quot;b&quot; : 2.3 } |



dbfiddle here

You can use row_to_json Postgres function.




create table foo(f1 int, f2 varchar(10), f3 float, f4 decimal(18,2));
insert into foo values (2, 'name', 2.345, 23.23);






select row_to_json(f)
from   (select f1,f2,f3,f4 from foo) f;



| row_to_json                                |
| :----------------------------------------- |
| {&quot;f1&quot;:2,&quot;f2&quot;:&quot;name&quot;,&quot;f3&quot;:2.345,&quot;f4&quot;:23.23} |



dbfiddle here