PostgreSQL jsonb_typeof() Function
Summary: in this tutorial, you will learn how to use the PostgreSQL jsonb_typeof()
function to return the type of the top-level JSON value as a text string.
Introduction to the PostgreSQL jsonb_typeof() function
The jsonb_typeof()
function allows you to get the type of a top-level JSONB value as a text string.
Here’s the syntax of the jsonb_typeof()
function:
In this syntax:
jsonb_value
is a JSONB value of which you want to get the type as a text string.
The jsonb_typeof()
function returns a text string representing the type of the input JSONB value. The possible return values are object, array, string, number, and null.
PostgreSQL jsonb_typeof() function examples
Let’s take some examples of using the jsonb_typeof()
function.
The following example uses the jsonb_typeof()
function to return the type of a JSON object:
Output:
The following example uses the jsonb_typeof()
function to return the type of a JSON array:
Output:
The following example uses the jsonb_typeof()
function to return the type of a number:
Output:
The following example uses the jsonb_typeof()
function to return the type of null:
Output:
The following example uses the jsonb_typeof()
function to return the type of string:
Output:
Summary
- Use the
jsonb_typeof()
function to return the type of the top-level JSON value as a text string.