I have a table with a VARCHAR column I use as JSON. In the column is the following data: {"Key-Name": "A value."}
.
If I use JSON_VALUE to filter on this column with the query below I get the following error: "JSON path is not properly formatted. Unexpected character '-' is found at position 5.".
SELECT *
FROM [MyTable]
WHERE JSON_VALUE([Value], N'$.Key-Name') = 'A value'
How can I retrieve values with the JSON_VALUE function when keys have special characters in them?
You can use double quotes to escape the key name:
SELECT *
FROM [MyTable]
WHERE JSON_VALUE([Value], N'$."Key-Name"') = 'A value'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With