- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert JSON file to CSV file using PowerShell?
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.JSON stored 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 : 9000 ApplicationName : TestApp MaintenanceWindow : Every Saturday BusinessUnit : IT AppOwner : Josh AppID : 1jj2221-223443s Location : 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
- Related Articles
- How to convert JSON to CSV file using PowerShell?
- 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?
- 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?
- Write a Python code to read JSON data from a file and convert it to dataframe, CSV files
- How to save a matrix as CSV file using R?
- How to search in the file using PowerShell?
- How to mount the ISO file using PowerShell?
- How to dismount the ISO file using PowerShell?

Advertisements