Username
Username

Reputation: 3663

How do I make an object within json_build_object()?

I have a Postgres query that starts like this.

SELECT json_build_object( 
    'type', 'Feature', 
    'properties', pop_density, 
)

That returns something like {"type":"Feature", "properties":10000}. I want it to return {"type":"Feature", "properties": {pop_density: 10000}}.

How do I change my query to reflect that?

Upvotes: 0

Views: 278

Answers (1)

jimmu
jimmu

Reputation: 1056

call json_build_object to make 'properties' object

select json_build_object('type', 'type_val', 'properties', 
                                             json_build_object('pop_density', 'pop_val'));

Upvotes: 1

Related Questions