We keep some JSON's in our database as NVARCHAR. Before inserting, we validate JSON with "IsJSON" function. The problem is we have a JSON with Accent character in the keys like "Malārd". IsJson returns 1 which means it is a valid JSON but when we try to use it in a path such as '$.Malārd' it will cause below error:
-- QUERY
SELECT JSON_VALUE(N'{"Malārd":1000}', N'$.Malārd')
-- OUTPUT
-- JSON path is not properly formatted. Unexpected character 'ā' is found at position 5
If I have to, I will prevent inserting accent characters in keys, but I hope to find a better solution for that.
I know that I can replace accent character and use trick like COLLATE LATIN1_GENERAL_CS_AI but we have some infrastructure tools and API's in our project which allowed client developer insert and grabs a variety of JSON models.
You need to surround path expression with quotes if the key name starts with a dollar sign or contains special characters:
SELECT JSON_VALUE(N'{"Malārd":1000}', N'$."Malārd"')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.