JSON_VALUE path "$" returns NULL when it contains data

2k views Asked by At

I have a column data consisting of {"name":["John","Peter"],id:["20","30"]}

If I do

SELECT JSON_VALUE(data,'$.name[0]') from table

it returns John but doing

SELECT JSON_VALUE(data,'$') from db
SELECT JSON_VALUE(data,'$.name') from table

returns NULL in both.

How come it does not return:

{"name":["John","Peter"],id:["20","30"]}
["John","Peter"]
1

There are 1 answers

4
Eldar On BEST ANSWER

As mentioned in the remarks section of the JSON_VALUE documentation there is a table that says for tags array in the json says: Use JSON_QUERY instead.

SELECT json_query(j,'$.name') from a;

Fiddle