Stephen
Stephen

Reputation: 23

Parsing JSON in SQL Server with JSON attribute having a number in its name

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.

Upvotes: 0

Views: 1630

Answers (1)

Zhorov
Zhorov

Reputation: 29993

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

Upvotes: 3

Related Questions