json_each()

A function expanding the top-level JSON object into a set of key/value pairs

json_each() is a system function which expands the top-level JSON object into a set of key/value pairs, with the value returned as json.

json_each() was added in PostgreSQL 9.3.

Usage

json_each ( json ) → setof record ( key text, value json )

To extract the value as text, use json_each_text().

Change history

Examples

Basic usage example for json_each():

postgres=# SELECT key, value, json_typeof(value)
             FROM json_each('{"a":"foo", "b":{"bar":"baz"}}');
 key |     value     | json_typeof 
-----+---------------+-------------
 a   | "foo"         | string
 b   | {"bar":"baz"} | object
(2 rows)

Categories

JSON, System function

See also

json_each_text(), json_object_keys(), jsonb_each()