SOLVED

ConvertFrom-Json with content like $$ or $^

Copper Contributor

trying figure out on how I can store $$ and $^ in a json object or file and then convert it from JSON to a customObject with the right content in PowerShell

But seemingly I have no option to escape the $$ in the same way as the \ on the json side 

And also no parameter for ConvertFrom-Json

 

 

@"
{
"bla": "^$$WS\\:$^W'"
}
"@ | ConvertFrom-Json

 

 

Did anyone have the same problem and was able to solve it?

2 Replies
You need to use the ` to tell powershell not to parse the $

@"
{
"bla": "^`$`$WS\\:`$^W'"
}
"@ | ConvertFrom-Json
best response confirmed by Mottz84 (Copper Contributor)
Solution

@Mottz84 

 

Yeah, either what @farismalaeb said or use literal quoting instead around the text block like so (assuming you're not trying to do any internal variable replacements):

 

@'
{
"bla": "^$$WS\\:$^W'"
}
'@ | ConvertFrom-Json

Cheers,

Lain

1 best response

Accepted Solutions
best response confirmed by Mottz84 (Copper Contributor)
Solution

@Mottz84 

 

Yeah, either what @farismalaeb said or use literal quoting instead around the text block like so (assuming you're not trying to do any internal variable replacements):

 

@'
{
"bla": "^$$WS\\:$^W'"
}
'@ | ConvertFrom-Json

Cheers,

Lain

View solution in original post