PostgreSQL 18 reference · JSON Functions

PostgreSQL JSON_VALUE() Function

Extract one scalar from JSON with an SQL/JSON path and return it as a chosen SQL type. Added in PostgreSQL 17.

PostgreSQL 18 Since 17

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

Syntax

JSON_VALUE(json, path RETURNING type [DEFAULT ... ON EMPTY | ON ERROR])

Parameters

ParameterDescription
json The JSON document.
path A path to a single scalar.
RETURNING optional The SQL type of the result. Default: text

Return value

A scalar of the requested type.

Examples

Typed extraction
SELECT JSON_VALUE('{"price":"12.50"}', '$.price' RETURNING numeric) * 2 AS doubled;

Output

 doubled
---------
   25.00
(1 row)

Run this on your computer — see “Get Started” for setup.

A default when missing
SELECT JSON_VALUE('{"a":1}', '$.missing' DEFAULT 'none' ON EMPTY) AS with_default;

Output

 with_default
--------------
 none
(1 row)

Run this on your computer — see “Get Started” for setup.

Version history

VersionChange
PostgreSQL 17Added

Was this page helpful?