- 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 to CSV file using PowerShell?
To convert the JSON to the CSV format we need to first use the ConvertFrom-JSON command. For example, we have already JSON file present with us at the C:\temp\VMinfo.JSON location. We will first import this file and then convert it to CSV as shown below.
Get-Content C:\Temp\VMInfo.json | ConvertFrom-Json | Export-Csv C:\Temp\vminfo.csv -NoTypeInformation
Suppose you have cmdlet that produces output in the hash table format as shown below.
PS C:\> Get-AzVM -VMName TestMachine2k16 | Select -ExpandProperty Tags Key Value --- ----- For Ansible Patching_Day Sunday Application SecretTag Owner Chirag
So we first need to convert the hash output to the JSON format and then from the JSON, we can save the output to excel.
PS C:\> Get-AzVM -VMName TestMachine2k16 | Select -ExpandProperty Tags | ConvertTo-Json | ConvertFrom-Json | Export-Csv C:\temp\Vmtags.csv -NoTypeIn formation
Advertisements