Summary: in this tutorial, you will learn how to use the PostgreSQL jsonb_pretty() function to convert a JSON value to a human-readable, indented format.
Introduction to the PostgreSQL jsonb_pretty() function
The jsonb_pretty() function allows you to convert a given JSONB value to a human-readable, indented format.
Here’s the basic syntax of the jsonb_pretty() function:
In this syntax:
jsonb_value is a JSONB value that you want to convert.
The jsonb_pretty() function returns a text that is the human-readable and indented format of the input JSONB value.
PostgreSQL jsonb_pretty() function examples
Let’s explore some examples of using the jsonb_pretty() function.
1) Basic PostgreSQL jsonb_pretty() function example
The following example uses the jsonb_pretty() function to format a JSONB value:
Output:
2) Using PostgreSQL jsonb_pretty() function with table data
First, create a new table called recipes:
Second, insert some rows into the recipes table:
Third, format the JSONB data in the details column:
Output:
Summary
Use the jsonb_pretty() function to convert a JSON value to pretty-printed, indented text.