【问题标题】:Powershell JSON to CSV Conversion and ExportPowershell JSON 到 CSV 的转换和导出
【发布时间】:2020-11-27 04:08:50
【问题描述】:

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

我知道 CSV 列的标题应该是:noticeId,title,solicitationNumber,department,subTier,office,postedDate,type,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

谢谢,

【问题讨论】:

  • 你能发布((Get-Content -Path $getpath) | ConvertFrom-Json).results的输出吗?根据错误,它似乎是空的
  • 你的.results来自哪里?从您的数据文件看来,您应该改用 .opportunitiesData...

标签: json excel powershell csv


【解决方案1】:

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

解决办法很简单,把.results改成.opportunitiesData

你的行应该是:

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

【讨论】:

    猜你喜欢
    • 2015-08-23
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 2015-08-09
    • 2014-12-04
    • 1970-01-01
    • 2021-01-08
    • 2021-03-31
    相关资源
    最近更新 更多