我正在尝试将 JSON 数据(子节点)转换为带有客户列标题的表格格式。我能够通过数据获得确切的节点,但不知道如何将其转换为表格格式。到目前为止尝试的代码
$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
我要求这些数据以表格格式与客户标题一起使用,以便我可以将数据传递给另一个实体
Library Version
-------- -------
@angular/animations ~7.2.0
@angular/cdk ^7.2.0
@angular/material ^7.2.0
任何帮助将非常感激。谢谢!!
回答
设法得到它的解决方案。它是通过属性 - 带有循环的名称和值
$jsondata.dependencies | Foreach-对象 {
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
}