Variable that hold a Json String

I’m trying to retrieve a set of Octopus Variables that contain a Json string and then pass it through as a Json object.
e.g

#{each AppConfig in AppConfig_Json}
$JsonString = #{AppConfig | JsonEscape}
$Json = $JsonString | ConvertFrom-Json
#{/each}

This script does not work as it does not recognize $JsonString as a valid Json format. I suspect this is because of the usage of JsonEscape. Any ideas how I can get the Json string in a format that can be converted into a json object?

Regards
B.

Hi Binh,

Are you trying to use that JSON blob on a Powershell script step, or someplace else? Cause I can see you are using both Powershell and Octostache (#{each}) syntax there.

Dalmiro

Yes it’s Powershell script.

Regards
B.

image001.png

Hi Binh,

That syntax you were using doesn’t look like It’ll work. Could you send me:

  • A screenshot of your variables. I need to be able to see the full value of each variable, so you might wanna send the values as text in this reply.
  • An example of the JSON blob you want as end result.

Regards,
Dalmiro

It’s OK. I’ve worked out where I’m going wrong.
Here’s my powershell script.

#{each AppConfig in AppConfig_Json}
$String = ‘#{AppConfig}’
$String = $String -replace “rn”,""
$Json = $JsonString | ConvertFrom-Json
#{/each}