To convert the JSON file to the CSV file using PowerShell, we need to use the ConvertTo-CSV command as a pipeline.
For example, we have a JSON file called PatchingServer.JSONstored at C:\temp and its content is as below.
Example
PS C:\> Get-Content C:\Temp\PatchingServer.json{ "Port": "9000", "ApplicationName": "TestApp", "MaintenanceWindow": "Every Saturday", "BusinessUnit": "IT", "AppOwner": "Josh", "AppID": "1jj2221-223443s", "Location": "EastUS"}
We need to convert the above file to the CSV file so we will use the ConvertTo-CSV command but before that, we need the JSON file need to be converted from JSON format to table format using ConvertFrom-JSON so the ConvertTo-CSV command can make it into a readable format.
Example
PS C:\> Get-Content C:\Temp\PatchingServer.json |ConvertFrom-Json
Output
Port : 9000ApplicationName : TestAppMaintenanceWindow : Every SaturdayBusinessUnit : ITAppOwner : JoshAppID : 1jj2221-223443sLocation : EastUS
So the final command should be,
Example
Get-Content C:\Temp\PatchingServer.json | ConvertFrom-Json | ConvertTo-Csv
Output
"Port","ApplicationName","MaintenanceWindow","BusinessUnit","AppOwner","AppID","Location""9000","TestApp","Every Saturday","IT","Josh","1jj2221-223443s","EastUS"
With the last command, the table is converted to the headers and values. We can save this CSV file as well.
Example
Get-Content C:\Temp\PatchingServer.json | ConvertFrom-Json | ConvertTo-Csv | Out-File C:\Temp\Patching.csv
Output
Updated on: 15-Dec-2020
21K+ Views
- Related Articles
- How to convert JSON to CSV file using PowerShell?
- How to convert CSV File to PDF File using Python?
- How to edit the CSV file using PowerShell?
- How to retrieve CSV file headers using PowerShell?
- How to append data into a CSV file using PowerShell?
- Create a GUI to convert CSV file to Excel file using Python
- How to create a CSV file manually in PowerShell?
- How to Export and import CSV file manually in PowerShell?
- Importing / Exporting CSV file in PowerShell
- How to parse a CSV file using PHP
- How to install MSI file using batch file in PowerShell?
- How to read data from *.CSV file using JavaScript?
- How to Display Data from CSV file using PHP?
- Write a Python code to read JSON data from a file and convert it to dataframe, CSV files
- How to search in the file using PowerShell?
Advertisem*nts