Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON Parsing Issue - 'S' is an invalid escapable character within a JSON

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
like image 562
techno Avatar asked Mar 01 '23 16:03

techno


2 Answers

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.

like image 155
Lavya Gupta Avatar answered Mar 04 '23 16:03

Lavya Gupta


write this:

.\\SQLEXPRESS

you must write double backslash

like image 32
hassan kamarzadeh Avatar answered Mar 04 '23 15:03

hassan kamarzadeh