PostgreSQL 18 reference · JSON Functions
PostgreSQL JSONB_PRETTY() Function
Format a jsonb value as indented, multi-line text that is easy for people to read, such as in logs or reports.
PostgreSQL 18 Since 9.5
Syntax
jsonb_pretty(jsonb)
Parameters
| Parameter | Description |
|---|---|
jsonb |
A jsonb (or json) value. |
Return value
text.
Examples
SELECT jsonb_pretty('{"name":"Ada","tags":["math","code"]}') AS pretty;
Output
pretty
--------------------
{ +
"name": "Ada",+
"tags": [ +
"math", +
"code" +
] +
}
(1 row)Run this on your computer — see “Get Started” for setup.
SELECT jsonb_pretty(to_jsonb(c)) AS pretty FROM categories AS c WHERE category_id = 2;
Output
pretty
----------------------------
{ +
"name": "Electronics",+
"category_id": 2 +
}
(1 row)Run this on your computer — see “Get Started” for setup.
Version history
| Version | Change |
|---|---|
| PostgreSQL 9.5 | Added |
In other languages
JSON_PRETTY()· SQLite
Related
TO_JSONB()· Convert any SQL value, including a whole row, to jsonb. Rows become objects with column names as keys.- SQL String Functions · tutorial