JSON_VALUE cannot be used to access a key that occurs more than once in a docment. Eg if the key or any of its parents are arrays then the content cannot be accessed via JSON_VALUE unless the JSON_PATH expression uses indices to identify a particular member of the array.
We need to use JSON_TABLE to solve this one...
SQL> WITH A as
2 ( select 1 ID,
3 '{"arrays":[{"AAA":{"arrays":[{"BBB":{"fields":{"Name":"Max"}}},{"BBB":{"fields":{"Name":"Mike"}}}]}},{"AA
A":{"arrays":[{"BBB":{"fields":{"Name":"Mark"}}},{"BBB":{"fields":{"Name":"Matt"}}}]}}]}' BLOBFIELD
4 from DUAL
5 union all
6 select 2 ID,
7 '{"arrays":[{"AAA":{"arrays":[{"BBB":{"fields":{"Name":"Pat"}}},{"BBB":{"fields":{"Name":"Pete"}}}]}},{"AA
A":{"arrays":[{"BBB":{"fields":{"Name":"Paul"}}},{"BBB":{"fields":{"Name":"Pascal"}}}]}}]}' BLOBFIELD
8 from DUAL
9 )
10 SELECT distinct AP.ID
11 FROM A AP,
12 JSON_TABLE(
13 AP.BLOBFIELD,
14 '$.arrays[*]'
15 COLUMNS
16 NESTED PATH
17 '$.AAA.arrays[*]'
18 COLUMNS (
19 NAME VARCHAR2(32) PATH '$.BBB.fields.Name'
20 )
21 )
22 where NAME LIKE '%Pete%'
23
SQL> /
2
Just for completeness.
The reason you got no rows with JSON_VALUE is the default "NULL ON ERROR" behavior. This can be see by adding the ERROR OR ERROR clause as can be seen below
SQL> WITH A as
2 ( select 1 ID,
3 '{"arrays":[{"AAA":{"arrays":[{"BBB":{"fields":{"Name":"Max"}}},{"BBB":{"fields":{"Name":"Mike"}}}]}},{"AA
A":{"arrays":[{"BBB":{"fields":{"Name":"Mark"}}},{"BBB":{"fields":{"Name":"Matt"}}}]}}]}' BLOBFIELD
4 from DUAL
5 union all
6 select 2 ID,
7 '{"arrays":[{"AAA":{"arrays":[{"BBB":{"fields":{"Name":"Pat"}}},{"BBB":{"fields":{"Name":"Pete"}}}]}},{"AA
A":{"arrays":[{"BBB":{"fields":{"Name":"Paul"}}},{"BBB":{"fields":{"Name":"Pascal"}}}]}}]}' BLOBFIELD
8 from DUAL
9 )
10 SELECT AP.ID
11 FROM A AP
12 WHERE JSON_VALUE(
13 AP.BLOBFIELD format json,
14 '$.arrays.AAA.arrays.BBB.fields.Name'
15 ) LIKE 'peter%'
16 /
no rows selected
SQL> WITH A as
2 ( select 1 ID,
3 '{"arrays":[{"AAA":{"arrays":[{"BBB":{"fields":{"Name":"Max"}}},{"BBB":{"fields":{"Name":"Mike"}}}]}},{"AA
A":{"arrays":[{"BBB":{"fields":{"Name":"Mark"}}},{"BBB":{"fields":{"Name":"Matt"}}}]}}]}' BLOBFIELD
4 from DUAL
5 union all
6 select 2 ID,
7 '{"arrays":[{"AAA":{"arrays":[{"BBB":{"fields":{"Name":"Pat"}}},{"BBB":{"fields":{"Name":"Pete"}}}]}},{"AA
A":{"arrays":[{"BBB":{"fields":{"Name":"Paul"}}},{"BBB":{"fields":{"Name":"Pascal"}}}]}}]}' BLOBFIELD
8 from DUAL
9 )
10 SELECT AP.ID
11 FROM A AP
12 WHERE JSON_VALUE(
13 AP.BLOBFIELD format json,
14 '$.arrays.AAA.arrays.BBB.fields.Name'
15 ERROR ON ERROR
16 ) LIKE 'peter%'
17 /
FROM A AP
*
ERROR at line 11:
ORA-40470: JSON_VALUE evaluated to multiple values
SQL>