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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

jsonb_pretty(jsonb)

Parameters

ParameterDescription
jsonb A jsonb (or json) value.

Return value

text.

Examples

Pretty-print
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.

A row
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

VersionChange
PostgreSQL 9.5Added

In other languages

Was this page helpful?