Skip to content
masterclass Buddy

PostgreSQL · Function

json_agg

json_agg combines values from input rows into one JSON array. It includes nulls and supports ordering inside the aggregate call.

Last updated

Syntax

json_agg ( anyelement ORDER BY input_sort_columns ) → json

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • jsonb_agg
  • json_agg_strict
  • json_arrayagg
  • json_object_agg
  • to_json
  • to_jsonb

Source: PostgreSQL: Documentation: 18: 9.21. Aggregate Functions. Checked 2026-11-03.