You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用PowerShell提取JSON数组的display_value并导出指定字段到Excel

问题:PowerShell导出指定字段到Excel时数组/对象字段为空

我有一份存储在变量$data中的数据,其中assigned_to、opened_by、assignment_group为包含display_value属性的对象结构。需要导出number、state、priority、assigned_to、opened_by、assignment_group这些字段,且数组/对象类型的字段仅导出其display_value内容到Excel。

尝试执行的命令:

$data | Select number,state,priority,assigned_to,opened_by,assignment_group | Export-Excel -path "xxx"

执行结果:数组/对象类型的字段输出为空。

期望输出:这类字段显示对应的display_value文本内容。


解决方案

直接使用Select-Object选择对象类型字段时,PowerShell无法自动解析内部的display_value属性,需要通过计算属性手动提取目标值:

$data | Select-Object number, state, priority,
    @{Name='assigned_to'; Expression={$_.assigned_to.display_value}},
    @{Name='opened_by'; Expression={$_.opened_by.display_value}},
    @{Name='assignment_group'; Expression={$_.assignment_group.display_value}} |
Export-Excel -Path "xxx"

关键说明:

  • @{Name='字段名'; Expression={提取逻辑}} 是PowerShell的计算属性语法,用于自定义字段的输出内容
  • $_.字段名.display_value 直接访问对象内部的display_value属性,将其作为该字段的导出值
  • 普通字符串/数值类型的字段(如number、state)可直接保留原选择方式

内容的提问来源于stack exchange,提问作者Ramya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 21:52:30