Reference

json_agg

Django JSON Agg.

class json_agg.JSONArrayAgg(*args, **kwargs)

Aggregate as JSON array.

Parameters:
  • expression (Any) – expression that will be used as array values.

  • vendor_func – If provided, values will be wrapped with the specified function name in the given vendor. The actual keyword argument must replace “vendor” with the vendor name (e.g., “sqlite_func” for SQLite). This is particularly useful when “Cast” is not supported.

  • nested_output_field – Django’s model Field representing values inside the json.

  • **kwargs – same as the ones available in django’s Aggregate.

output_field = <django.db.models.fields.json.JSONField>
class json_agg.JSONObjectAgg(*args, **kwargs)

Aggregate as a JSON object.

Parameters:
  • name_expression (Any) – expression that will be used as JSON keys.

  • value_expression (Any) – expression that will be used as JSON values.

  • vendor_func – If provided, values will be wrapped with the specified function name in the given vendor. The actual keyword argument must replace “vendor” with the vendor name (e.g., “sqlite_func” for SQLite). This is particularly useful when “Cast” is not supported.

  • nested_output_field – Django’s model Field representing values inside the json.

  • **kwargs – same as the ones available in django’s Aggregate.

property convert_value: callable

Override BaseExpression.convert_value to handle json objects.

output_field = <django.db.models.fields.json.JSONField>