Existing custom snippet causes "Failed to import snippets - JSON value could not be converted"
TrailBear
Posts: 2 New member
I've read several reports of this error as I've been seeing it also. In my investigation I noticed that my ADS custom snippets are the problem while the error suggests that the issue is happening while processing my SSMS snippets. The problem is, I don't have any SSMS snippets, that file is untouched from installation.
I removed all my ADS snippets, the error went away.
I added back an example from the ADS documentation, and the error came back.
I added only comments to the ADS snippet file, and the comments were removed.
So, to me it seems that if SQL Prompt is trying to read my ADS custom snippets file sql.json (One MS documentation example only) as if it were the SSMS snippets file (empty on this machine), this causes an error, and the process stops before it can cause any harm to that file. However, if one replaces the contents of the ADS custom snippets file with just comments, SQL Prompt sees no errors, but replaces the contents with a pair of curly braces.
Some test info below:
I used only this code:
{
"Select top 5": {
"prefix": "sqlSelectTop5",
"body": "SELECT TOP 5 * FROM ${1:TableName}",
"description": "User-defined snippet example 1" }
}
Repro steps
{
// this comment should remain
}
Repro steps
I removed all my ADS snippets, the error went away.
I added back an example from the ADS documentation, and the error came back.
I added only comments to the ADS snippet file, and the comments were removed.
So, to me it seems that if SQL Prompt is trying to read my ADS custom snippets file sql.json (One MS documentation example only) as if it were the SSMS snippets file (empty on this machine), this causes an error, and the process stops before it can cause any harm to that file. However, if one replaces the contents of the ADS custom snippets file with just comments, SQL Prompt sees no errors, but replaces the contents with a pair of curly braces.
Some test info below:
Set up:
- SSMS and VStudio user snippets files are empty (default from install of those programs)
- Redgate SQL Prompt installed in ADS
- ADS is closed
Test One
Set up: Add a user snippet to ADS following this documentationI used only this code:
{
"Select top 5": {
"prefix": "sqlSelectTop5",
"body": "SELECT TOP 5 * FROM ${1:TableName}",
"description": "User-defined snippet example 1" }
}
Repro steps
- Start ADS
- Observe error appears lower right
- Open a new query, observe that the sqlSelectTop5 snippet works
- SQL prompt does not throw any error
- sqlSelectTop5 snippet works
- The following error occurs:
Failed to import snippets from SSMS: Error: Unhandled exception: System.Text.Json.JsonException: The JSON value could not be converted to System.String. Path: $.Select top 5.body | LineNumber: 3 | BytePositionInLine: 72.
Test Two
Set up: Update the ADS user snippets (sql.json) replacing all content with the following:{
// this comment should remain
}
Repro steps
- Start ADS
- Observe no error appears
- Open the ADS snippets file inspect for the comment added during set up
- SQL Prompt does not throw an error
- Snippet file is unaffected
- Snippet file comment is gone only a pair of curly braces remains