I have a table: Employee. Schema: (name varchar, preferences nvarchar(max)). where preferences is a json formatted string.
My query (that fails) is:
select JSON_QUERY(preferences, '$.personal')
from Employee
where ISJSON(preferences) = 1
and len(JSON_QUERY(preferences, '$.personal')) > 2
However, this query works:
select JSON_QUERY(preferences, '$.personal')
from Employee
where ISJSON(preferences) = 1
Also, if I:
create table tmp(name varchar(256), personal nvarchar(max))
insert into tmp
select name, JSON_QUERY(preferences, '$.personal') as personal
from Employee
where ISJSON(preferences) = 1
select personal
from tmp
where len(personal) > 2
Everything works fine.
Is this a SQL Server bug with JSON_QUERY() or am I doing something wrong?
(EDIT) Error message is:
JSON text is not properly formatted. Unexpected character 'n' is found at position 3.
(EDIT) Also fails:
select JSON_QUERY(preferences, '$.personal')
from Employee
where ISJSON(preferences) = 1
and JSON_QUERY(preferences, '$.personal') is not null