15.7 FIND_PATHS_LIKE Function

This function returns paths into p_values that match a given pattern.

Syntax

APEX_JSON.FIND_PATHS_LIKE (
    p_return_path      IN VARCHAR2,
    p_subpath          IN VARCHAR2 DEFAULT NULL,
    p_value            IN VARCHAR2 DEFAULT NULL,
    p_values           IN t_values DEFAULT g_values )
RETURN apex_t_varchar2;

Parameters

Table 15-3 FIND_PATHS_LIKE Function Parameters

Parameter Description

p_return_path

Search pattern for the return path..

p_subpath

Search pattern under p_return_path (optional).

p_value

Search pattern for value (optional).

p_values

Parsed JSON members. The default is g_values.

Returns/Raised Errors

Table 15-4 FIND_PATHS_LIKE Function Returns and Raised Errors

Return Description

apex_t_varchar2

Table of paths that match the pattern.

VALUE_ERROR

Raises this error if p_values(p_path) is not an array or object.

Example

This example parses a JSON string, finds paths that match a pattern, and prints the values under the paths.

DECLARE
    j            apex_json.t_values;
    l_paths apex_t_varchar2;
BEGIN
    apex_json.parse(j, '{ "items": [ { "name": "Amulet of Yendor", "magical": true }, '||
                                     { "name": "Slippers",  "magical": "rather not" } ]}');
    l_paths := apex_json.find_paths_like (
        p_values         => j,
        p_return_path => 'items[%]',
        p_subpath       => '.magical',
        p_value           => 'true' );
    dbms_output.put_line('Magical items:');
    for i in 1 .. l_paths.count loop
        dbms_output.put_line(apex_json.get_varchar2(p_values => j, p_path => l_paths(i)||'.name')); 
    end loop;
END;