How to escape/replace the special character

I have a variable like this

$variable = @{
“owner”= [“https”]

After I convertToJson, I want the output to be like this.

“owner”: [“https”]

How to achieve this, any help is appreciated. Thank you!

Could you please format your code as code here in the forum?
Thanks in advance.

How did you do that? Please share the code you used. ( formatted as code :wink: )

Do you mean the text of the JSON should look like this? That wouldn’t be a valid JSON format then if I got it right. :thinking:

Thank you @Olaf

here is my latest code. sure, I need the final value of owner should be wrapped in [ ]

$website = '[“https”]'

$variable = @{
“owner”= $website

$jsonOutput = $variable | ConvertTo-Json

write-host $jsonOutput

here is my output

    "owner":  "[“https”]"

But I need

    "owner":  [“https”]

Since square brackets are the indicator for arrays in JSON you may cast the content you want to an array.

$variable = @{
    "owner"= @("https")
$Variable | 

… outputs:

    "owner":  [

… and BTW: You should format code, sample data, error messages and console output as code here in the forum. :point_up:t3:


sure will do.
thank you @Olaf , you are the best!!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.