I'm using there functions to serialize and deserialize objects in Powershell 2.0 from question PowerShell 2.0 ConvertFrom-Json and ConvertTo-Json implementation
function ConvertTo-Json20([object] $item){
add-type -assembly system.web.extensions
$ps_js=new-object system.web.script.serialization.javascriptSerializer
return $ps_js.Serialize($item)
}
function ConvertFrom-Json20([object] $item){
add-type -assembly system.web.extensions
$ps_js=new-object system.web.script.serialization.javascriptSerializer
return $ps_js.DeserializeObject($item)
}
But when i run example:
$json = "[{'a':'b'},{'c':'d'}]"
$o = ConvertFrom-Json20 $json
$newJson = ConvertTo-Json20 $o
I've got error:
Exception calling "Serialize" with "1" argument(s): "A circular reference was detected while serializing an object of t
ype 'System.Management.Automation.PSParameterizedProperty'."
At line:4 char:28
+ return $ps_js.Serialize <<<< ($item)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
How can I resolve this error?
P.S. I apologize in advance. What was not able to add a comment to the original question ...