0

I am trying to parse a JSON file that is stored in a column of a SQL server table. I am using the JSON_VALUE function. But this function does not like it that the attribute (called 6Months) has a number in its name. And it is giving me an error for that reason. Is there a way to force the function read the file? Please see query and error message below. I greatly appreciate any help.

Select 
JSON_VALUE(JsonFile, '$.company.6Months.count') 
From dbo.Filestore

Msg 13607, Level 16, State 4, Line 3
JSON path is not properly formatted. Unexpected character '6' is found at position 10.
2

1 Answer 1

3

You need to use quotes in your path expression. As is mentioned in the documentation, if the key name starts with a dollar sign or contains special characters such as spaces, surround it with quotes.

SELECT JSON_VALUE(JsonFile, '$."company.6Months.count"') 
FROM dbo.Filestore
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot Zhorov, that solved it for me.
@Stephen you should consider changing that name. Even JavaScript would choke on 6Months if you used dot notation, ie myObject.6Months

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.