I have a string as given below
$mystring="t={p:1,q:2,r:3}"
i want to convert this string to a following string
"t={'p':'1','q':'2','r':'3'}"
How can i do this in powershell
Code i tried is given below
$list=[System.Text.RegularExpressions.Regex]::Matches($mystring,"[{:,]").Value
foreach($dicitem in $diclist)
{
$dic=$dic.Replace("$dicitem","$dicitem'")
}
$list=[System.Text.RegularExpressions.Regex]::Matches($dic,"[}:,]").Value
foreach($dicitem in $diclist)
{
$dic=$dic.Replace("$dicitem","'$dicitem")
}
But iam not getting the result as expected,is there any other better way to do this