It looks like Powershell cuts off data when exporting to JSON if it nests too deep. My object hierchy looks like this:
Main Object
Metadata
More Metadata
Collection of Other object Sources
Collection of data used by these sources
For some reason, when I convert to JSON, powershell exports the Third level (Collection of data used by these sources) as an empty string, even though it is an array of objects with various NoteProperties added to them. For example:
$test = New-Object -TypeName PSObject
$obj = New-Object -TypeName PSObject
$obj | Add-Member -MemberType NoteProperty -Name "Name" -Value "adsf"
$test2 = New-Object -TypeName PSObject
$test2 | Add-Member -MemberType NoteProperty -Name "ArrayTest" -Value @($obj, $obj)
$test3 = New-Object -TypeName PSObject
$test3 | Add-Member -MemberType NoteProperty -Name "ArrayTest" -Value @($obj, $obj, $obj)
$test | Add-Member -MemberType NoteProperty -Name "CollectionTest" -Value @($test2, $test3)
This results in the following JSON String:
PS C:UsersuserprojectsPowershell> $test | ConvertTo-Json
{
"CollectionTest": [
{
"ArrayTest": " "
},
{
"ArrayTest": " "
}
]
}
Converting to XML results in a similar situation:
<?xml version="1.0"?>
<Objects>
<Object Type="System.Management.Automation.PSCustomObject">
<Property Name="CollectionTest" Type="System.Object[]">
<Property Type="System.Management.Automation.PSCustomObject">
<Property Type="System.String">@{ArrayTest=System.Object[]}</Property>
<Property Name="ArrayTest" Type="System.Management.Automation.PSNoteProperty">System.Object[]</Property>
</Property>
<Property Type="System.Management.Automation.PSCustomObject">
<Property Type="System.String">@{ArrayTest=System.Object[]}</Property>
<Property Name="ArrayTest" Type="System.Management.Automation.PSNoteProperty">System.Object[]</Property>
</Property>
</Property>
</Object>
</Objects>
Is there some sort of object nesting limitation in powershell?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…