21.10. Aggregating Values into a JSON Object (json_group_object) #

Required privileges: Postgres Pro AXE administrator only. For a full list of stored procedures and privileges, refer to Section 12.1.

Execute the following command on the Postgres Pro AXE server:

  SELECT json_group_object(keys, values) ON CONFLICT DO NOTHING;

Where:

  • keys: The keys that must be aggregated into a JSON object.

  • values: The values that must be aggregated into a JSON object.

Postgres Pro AXE returns a JSON object with all key-value pairs from the aggregation.

Example 21.10. Executing the json_group_object Stored Procedure

Data in the example1 table:

  k       v
  duck    42
  goose   7

Aggregating values into a JSON object:

  SELECT json_group_object(k, v) FROM example1;
  {"duck":42,"goose":7}