# jsonb_object_agg

Aggregate key/value pairs with final-key-wins semantics.

**Syntax**

```text
jsonb_object_agg(key,value [ORDER BY ...])
```

**Arguments**

Non-NULL scalar keys; NULL values are retained. Only final values per unique key are retained. FILTER, DISTINCT and ordinary windows apply; specify ORDER BY when duplicate-key order matters.

**Returned value**

Canonical native JSON object, or SQL NULL for empty input.

**Examples**

```sql
CREATE TABLE attributes (name TEXT, value INTEGER);
INSERT INTO attributes VALUES ('a',1),('a',2);
```

```sql
SELECT jsonb_object_agg(name,value) FROM attributes FORMAT csv;
```

```text
"{""a"":2}"
```
