I have the following JSON in appsettings
file , it has a connection string.
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"ApplicationInsights": {
"InstrumentationKey": "8eje88w0-1509-4ae0-b58c-1a7ee5b9c7e4"
},
"ConnectionStrings": {
"DefaultConnString": "Server=MYPC\SQLEXPRESS;Database=CoreService.Mark;Trusted_Connection=True;"
},
"AllowedHosts": "*"
}
But upon executing the program.I keep getting the following error.I tried to find any errors,but could not locate any.Please advice
Unhandled exception. System.FormatException: Could not parse the JSON file.
---> System.Text.Json.JsonReaderException: 'S' is an invalid escapable character within a JSON string. The string should be correctly escaped. LineNumber: 10 | BytePositionInLine: 42
In your ConnectionStrings. DefaultConnString
field, you're escaping S
(before SQLExpress;
). As the error suggests, you can't do that.
You can fix this by adding another escape character (backslash, \
) in front of the pre-existing one. Backslashes are escapable characters and the end result will be the wanted one, you'll get one backslash in that position.
write this:
.\\SQLEXPRESS
you must write double backslash
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