如何将powershell json响应转换为csv

如何将powershell json响应转换为csv,json,powershell,api,csv,Json,Powershell,Api,Csv,这是我的PowerShell,它正在调用API并返回JSON响应 $output = Get-SurveyParticipents ` -url "https://orxsurveys.limequery.com/admin/remotecontrol" ` -session $sessionKey ` -id "519965" ` -start "0" ` -limit "2" ` -unused $F

这是我的PowerShell,它正在调用API并返回JSON响应

$output = Get-SurveyParticipents `
 -url "https://orxsurveys.limequery.com/admin/remotecontrol" `
 -session $sessionKey `
 -id "519965" `
 -start "0" `
 -limit "2" `
 -unused $False `
 -attributes ["completed", "usesleft"]

($output | Export-Csv -NoTypeInformation ./testtt.csv)
写入主机$output生成:

@{tid=6; token=35ddmyQTlNpzLat; participant_info=} @{tid=7; token=nQ_S838LjYT4mR6; participant_info=}
导出CSV生成:

这是我需要从导出csv生成的内容:


有人能告诉我如何将“参与者信息”转换为CSV导出的有效json吗正如您所知,除了将PowerShell用于SharePoint之外,我对PowerShell没有什么经验。谢谢大家!

您的目标是输出具有自定义属性集的对象(因为它与原始对象不同)。这可以通过和计算属性来完成

$output | 
    Select-Object tid,token,
        @{n='Firstname';e={$_.participant_info.Firstname}},
        @{n='Lastname';e={$_.participant_info.Lastname}},
        @{n='Email';e={$_.participant_info.Email}} |
            Export-CSV testtt.csv -NoType

您的目标是输出具有自定义属性集的对象(因为它与原始对象不同)。这可以通过和计算属性来完成

$output | 
    Select-Object tid,token,
        @{n='Firstname';e={$_.participant_info.Firstname}},
        @{n='Lastname';e={$_.participant_info.Lastname}},
        @{n='Email';e={$_.participant_info.Email}} |
            Export-CSV testtt.csv -NoType

非常感谢你。这项工作,我将研究选择的对象现在非常感谢你们。这是可行的,我现在将研究Select对象,它不是json$输出看起来像是由write-host转换为字符串的对象。感谢您澄清:)这不是json$输出看起来像是写入主机转换为字符串的对象。感谢您的澄清:)