Powershell convertfrom-json | convertto-csv

前端 未结 1 1793
猫巷女王i
猫巷女王i 2020-12-17 01:43

I have a JSON data structured as following (there may be some mistakes here, the data I\'m using is fine):

[{
\"id\": 12345,
\"itemName\": \"some string\",
\         


        
相关标签:
1条回答
  • 2020-12-17 01:54

    In short you need to do something like this:

    (Get-Content file.json -Raw | ConvertFrom-Json) | Select id,itemName,sellerId | Convertto-CSV -NoTypeInformation
    

    The first problem was that Get-Content was passing individual lines to ConvertFrom-Json which is not what it wants. Using the -Raw switch passes it in its entirety.

    The (Get-Content file.json -Raw | ConvertFrom-Json) needs to be in parentheses as that allows us to continue with the pipe. The properties are not accessible without doing this. It looks like it is trying to pass the entire object instead of its individual parts down the pipe.

    -NoTypeInformation removes lines like this

    #TYPE Selected.System.Management.Automation.PSCustomObject
    
    0 讨论(0)
提交回复
热议问题