PostgreSQL jsonb_pretty() Function
The PostgreSQL jsonb_pretty()
function uses whitespace indentation and newlines to convert a given JSONB value into a formatted, more readable text.
jsonb_pretty()
Syntax
This is the syntax of the PostgreSQL jsonb_pretty()
function:
jsonb_pretty(json_value JSONB) -> TEXT
Parameters
json_value
-
Required. The JSONB value to convert.
Return value
The PostgreSQL jsonb_pretty()
function returns a text string representing the given JSONB value, indented with spaces and newlines, for easier reading.
If you provide a NULL parameter, the jsonb_pretty()
function will return NULL.
jsonb_pretty()
Examples
The following example shows how to use the PostgreSQL jsonb_pretty()
function to beautify the output of a given JSON array.
SELECT jsonb_pretty('[1, 2, 3, [4, 5]]');
jsonb_pretty
--------------
[ +
1, +
2, +
3, +
[ +
4, +
5 +
] +
]
The following example shows how to use the PostgreSQL jsonb_pretty()
function to beautify the output of a given JSON object.
SELECT jsonb_pretty('{"x": 1, "y": "a", "z": [1, 2]}');
jsonb_pretty
---------------
{ +
"x": 1, +
"y": "a",+
"z": [ +
1, +
2 +
] +
}