Author Posts

June 20, 2016 at 6:55 pm

Hello,

I have JSON which has collection of elements and I need to remove and element and then save JSON. I'm lost as far as what do I need to use to remove an element.

PS C:\windows\system32> $jsonFile.resourcePackages

resourcePackage                                                         
---------------                                                         
@{name=SynopticPanelBySQLBI1447436165337; type=0; items=System.Object[]}
@{name=YourVisual1465156444568; type=0; items=System.Object[]}          
@{name=BulletChartBySQLBI1459586236884; type=0; items=System.Object[]}  
@{name=CandleStickBySQLBI1458002061454; type=0; items=System.Object[]}  
@{name=SmartFilterBySQLBI1465232218990; type=0; items=System.Object[]}  
@{name=SmartFilterBySQLBI1465231403311; type=0; items=System.Object[]}  



PS C:\windows\system32> $jsonFile.resourcePackages.Remove(0)
Exception calling "Remove" with "1" argument(s): "Collection was of a fixed size."
At line:1 char:1
+ $jsonFile.resourcePackages.Remove(0)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NotSupportedException

June 24, 2016 at 4:35 pm

If you've turned this into a proper object (ConvertFrom-Json), you could...

$json | where { $_.whatever -eq 'something' } | convertto-json | out-file whatever.js

As a kind of basic approach. Use Where-Object to filter out the item(s) you don't want.