Thursday, July 29, 2021

Converting a file with .json format to a file with .csv format using PowrShell

  The easiest way to do this is to use Windows Powershell as described here. It is enough if you convert .json to .csv. File format .cssv can be opened with EXCEL and saved.

This is the .json file:

============

{

   "Name": "James Bond",

   "Age": "35",

   "Profession": "Professional Killer",

   "Location": "London, UK"

}

===================

This file, JamesBond.json  is saved on my desktop.

Let us say that is the code you need to convert to from .json to .csv format

Create the above text in Notepad and save it with the extension .json (default is .txt for Notepad)


Open the Windows PowerShell ISE




Type in the following code (try to see what else you can convert from and convert to in the above images):

Get-Content C:\Users\TestUser\Desktop\JamesBond.json | ConvertFrom-Json|ConvertTo-Csv

Run the code in the Windows PowerShell ISE

You will see this result:

==========================

"Name","Age","Profession","Location"

"James Bond","35","Professional Killer","London, UK"

---------------------------------

You get the answer as shown. 

This is in CSV format and this can be opened with EXCEL.


This can be saved as .xlsx or various other formats.






No comments:

DMCA.com Protection Status