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"]
$.namedoesn't contain a scalar value, it contains an array. What are the actual results you are after here? If you simply want the JSON data, then don't useJSON_VALUE, just referencedata. (Also, I hope you don't have a table calleddb, that's a little confusing; a table isn't a database, a table is a database object.)name(based on learn.microsoft.com/en-us/sql/relational-databases/json/…). Agreed with thedb- I have changed it now for clarification.