Function jsonb_extract_path

Source
pub fn jsonb_extract_path(
    v: JsonbRef<'_>,
    path: impl Row,
) -> Option<JsonbRef<'_>>
Expand description

Extracts JSON sub-object at the specified path, where path elements can be either field keys or array indexes.

  • jsonb #> text[] → jsonb
  • jsonb_extract_path ( from_json jsonb, VARIADIC path_elems text[] ) → jsonb

§Examples

query T
select '{"a": {"b": ["foo","bar"]}}'::jsonb #> '{a,b,1}'::text[];
----
"bar"

query T
select '{"a": {"b": ["foo","bar"]}}'::jsonb #> '{a,b,null}'::text[];
----
NULL

query T
select jsonb_extract_path('{"a": {"b": ["foo","bar"]}}', 'a', 'b', '1');
----
"bar"

query T
select jsonb_extract_path('{"a": {"b": ["foo","bar"]}}', variadic array['a', 'b', '1']);
----
"bar"