smroy
Posts: 2
Joined: Tue Mar 23, 2021 6:31 pm

JSON Edit file doubles backslashes messing my connection string

Hi,

I have a appsettings.json file for my net core app. I used the json file option of version 18 to create the file using properties.

My connection string is in this file. Instance name is in this format "serverName\\InstanceName" and is stored in a property. When I setup a string node in my json file, I put the property as the value.

My problem is, when I install, the resulting json file shows "serverName\\\\InstanceName", wich messes up my connection.

Is there a way to not escape these characters?

Im pretty sure it's working as intended with XML files when i worked with .net framework web.config files.

Any inputs on that ?

Thanks
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: JSON Edit file doubles backslashes messing my connection string

Hello and welcome to our forums,

I have tested this scenario and I was indeed able to reproduce it on my end.

Please note, however, that the behavior is the expected one, as it is expected for the backslash character to be escaped in a JSON file.

I will need to consult with the developer of this feature about your scenario.

I will update this thread as soon as we will reach a conclusion.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: JSON Edit file doubles backslashes messing my connection string

Hello,

I have discussed this with our developer and a solution for this would be to pass a value containing a single "\" character to your property, e.g.:

Name: CONNECTION_STRING
Value: ServerName\InstanceName


instead of:

Value: ServerName\\InstanceName

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
smroy
Posts: 2
Joined: Tue Mar 23, 2021 6:31 pm

Re: JSON Edit file doubles backslashes messing my connection string

Hi, thank you for the reply.

While writing a json file with a property with a fixed value putting a single \ is acceptable. However, when updating a json in an upgrade, the installer read the property (eg: ServerName\\InstanceName ) and double escape it in the writing process. So each upgrade result in a double character escaping from the previous version.

Let me know if i'm not clear enough in my explanation, thank you
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: JSON Edit file doubles backslashes messing my connection string

Hello,

First of all, please accept my apologies for such a delayed reply (I was off last week due to not feeling well).

What you are saying does indeed make sense. However, I was not quite able to reproduce this on my end.

If possible, could you please create a sample project that reproduces this and forward it to me (together with a sample JSON file) so I can further test this?

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”