September 4th, 2019

PowerTip: Read a JSON configuration file as a PowerShell object

Doctor Scripto
Scripter

Summary: Using the ConvertFrom-Json Cmdlet in PowerShell to read a JSON formatted file

A picture containing scissors

Description automatically generated

Hey, Doctor Scripto! I’ve seen a lot of JSON files in use in Azure. I’m not very good with editing JSON properly. Is there an easy way to read this and at least edit it with PowerShell?

Most definitely my good friend. For the file below called “settings.json” you can convert it to a PowerShell Object for editing purposes using the following line.   Once you have completed this, you can manipulate it like any other PowerShell Object.

$PowerShellObject=Get-Content -Path settings.json | ConvertFrom-Json

PowerShell, Doctor Scripto, Sean Kearney, PowerTip, JSON

 

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.