How to save a JSON object to a file using Powershell?

后端 未结 6 567
情话喂你
情话喂你 2021-02-01 15:10

I have converted the following JSON file to powershell representation object.

{
\"computer\": [
    {
        \"children\": [   
            {   
                        


        
6条回答
  •  隐瞒了意图╮
    2021-02-01 15:41

    1) The below command can be used to convert a json to CSV

    Example: Get-Content package.json | Out-String | ConvertFrom-Json | Select parameter1, parameter2, parameter3 | ConvertTo-Csv -NoTypeInformation | Format-Table >> C:\JenkinsWorkspace\Result.csv

    Get-Content: This is like "cat" command in linux which will get all data of file "package.json" and converts from Json (Using ConvertFrom-Json function) extracting the details of only required parameters and then converting them into CSV using "ConvertTo-Csv" function without any unwanted Type Headers and formatting them into Table.

    2) The above result can also be formatted into proper csv to view it as Excel format without any duplicates and also having Text-To-Column conversion using below command:

    Import-Csv "C:\Result.csv" -delimiter "," | Sort-Object _from -Unique | Export-csv "C:\FINAL_REPORT_$date.csv"

提交回复
热议问题