Powershell JSON到CSV的转换和导出

大酒杯

我有以下JSON文件(Invoke-RestMethod调用的示例输出)https://filebin.net/t3dtujxnssr6dcic/0.json?t=j2lr5rnb我正在尝试运行Powershell命令将其导出到CSV,但始终遇到错误,导致CSV为空或仅显示SystemObject的一行。

我知道CSV列的标题应该是:noticeId,title,solicitationNumber,部门,subTier,办公室,postedDate,类型,baseType,archiveType,archiveDate,typeOfSetAsideDescription,typeOfSetAside,responseDeadLine,naicsCode,classificationCode,active,award,pointOfContact,description ,organizationType,officeAddress,placeOfPerformance,additionalInfoLink,uiLink,links / 0,resourceLinks

我的命令是:

((Get-Content -Path $getpath) | ConvertFrom-Json).results | Export-CSV -Path $topath -NoTypeInformation

我最终收到以下错误:

Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.
At line:1 char:61
+ ... nvertFrom-Json).results | Export-CSV -Path $topath -NoTypeInformation
+                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCo
   mmand

谢谢,

阿德里安·伊利亚纳(Adrian Ileana)

正如评论中提到的,您似乎正在尝试检索JSON文件中“ opportunitiesData”字段下存储的数据。

解决方案就像更改.results.opportunitiesData

您的行应为:

((Get-Content -Path $getpath) | ConvertFrom-Json).opportunitiesData | Export-CSV -Path $topath -NoTypeInformation

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章