I am trying to convert JSON data(Childnodes) to tabular format with a Customer column header. I am able to get the exact node via data ,but not sure how to convert it to tabular format. Code tried so far
$extensionfile = "C:\Test\Package.json"
$jsondata = Get-Content -Raw -Path $ExtensionFile | ConvertFrom-Json
$jsondata.dependencies
@angular/animations : ~7.2.0 @angular/cdk : ^7.2.0 @angular/common : ~7.2.0 @angular/compiler : ~7.2.0 @angular/core : ~7.2.0 @angular/forms : ~7.2.0 @angular/material : ^7.2.0 @angular/platform-browser : ~7.2.0 @angular/platform-browser-dynamic : ~7.2.0 @angular/router : ~7.2.0 @types/uuid : ^3.4.5 alertifyjs : ^1.10.0 angular7-material-table : ^1.0.2 animate.css : ^3.5.0 bootstrap : ^3.4.1 core-js : ^2.5.4 fastclick : ^1.0.6 file-saver : ^2.0.2 font-awesome : ^4.6.3 gentelella : ^1.4.0 jquery : ^3.4.1 material-table : ^1.50.0 moment : ^2.24.0 ng-knife : ^0.2.8 ngx-bootstrap : ^4.3.0 nprogress : ^0.2.0 rxjs : ~6.3.3 tslib : ^1.9.0 uuid : ^3.3.2 xlsx : ^0.15.1 zone.js : ~0.8.26
I required to this data in a tabular format with customer header, so that i can pass the data to another entity
Library Version
-------- -------
@angular/animations ~7.2.0
@angular/cdk ^7.2.0
@angular/material ^7.2.0
Any help would be much appreciated. Thank you!!
Answer
Managed to get the solution for it. It is via property - Name and Value with a loop
$jsondata.dependencies | Foreach-Object {
foreach ($property in $_.PSObject.Properties)
{
#echo $property.Name, $property.Value
$property | Select-Object @{Name="Application Name"; Expression={$appname}},@{Name="Type of Library"; Expression={"NodeJS"}}, @{Name="Library"; Expression={$property.Name}} , @{Name="version"; Expression={$property.Value}}, @{Name="CompanyName"; Expression={"No Data"}}, @{Name="Config"; Expression={$findnodelibs.FullName}} | Export-Csv -NoTypeInformation -Append ./Test.csv
}
$jsondata.dependenciescontains a single, multi-line string with space-padded columns? Take a look at how your question renders - the output format is not at all clear.$jsondata.dependencies.GetType().FullNamegives you. (looks like a hashtable or an array of PSObjects to me)