Json transformation escaped charecters

louis.chilson's Avatar

louis.chilson

13 Nov, 2017 04:47 PM

I have a octo variable that gets replaced with a \\ in the value instead of what it is in octopus a single \

am i missing something?

  1. Support Staff 1 Posted by Kenneth Bates on 14 Nov, 2017 03:16 AM

    Kenneth Bates's Avatar

    Hi Louis,

    Thanks for getting in touch! I'm sorry you're hitting this issue. How did you create this variable (i.e. via the API or in the UI)?
    Are you using the JSON configuration variables feature and defining your JSON file in there?

    I gave a quick test using the Substitute variables in files feature and it correctly substituted the variable value without adding the extra \. You would just need to enable this feature, define the JSON file and use the syntax #{VariableName} in your JSON file (where you want it substituted). You can refer to more info on this feature in our docs.
    https://octopus.com/docs/deploying-applications/substitute-variable...

    Would this method work for your situation?

    I look forward to hearing back!

    Best regards,

    Kenny

  2. 2 Posted by louis.chilson on 14 Nov, 2017 04:20 PM

    louis.chilson's Avatar

    i was using the JSON configuration variables
    i tried using ConnectionStrings:ServicesContext as that varaible but it always replaces as

    "ServicesContext": "Server=.server\db;Database=db;Trusted_Connection=True;"

    ill try variable replacement but id much rather use the other.

    {
      "ConnectionStrings": {
        "ServicesContext": "Server=.server\db;Database=db;Trusted_Connection=True;"
      },
      "Logging": {
        "IncludeScopes": false,
        "Debug": {
          "LogLevel": {
            "Default": "Warning"
          }
        },
        "Console": {
          "LogLevel": {
            "Default": "Warning"
          }
        }
      }
    }
    
  3. Support Staff 3 Posted by Kenneth Bates on 15 Nov, 2017 05:23 AM

    Kenneth Bates's Avatar

    Hi Louis,

    Thanks for following up. After some more testing to get this working properly using the JSON configuration variables feature, unfortunately I've had no luck. It comes down to the fact that a single backslash isn't valid JSON, and the solution we recommend here is to use the Substitute variables in files feature as I mentioned beforehand. Were you able to get this working?

    If you're still wanting to use the JSON feature, perhaps a solution would be to escape the backslash, as outlined here.
    https://realguess.net/2016/07/29/escaping-in-json-with-backslash/

    You can also validate JSON with this cool tool.
    https://jsonlint.com/

    I hope this helps! Let me know if you have any further questions or concerns going forward. :)

    Kind regards,

    Kenny

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac