To manipulate JSON files with PowerShell, you can use the ConvertFrom-JSON cmdlet to parse JSON data into PowerShell variables, and the ConvertTo-Json cmdlet to convert PowerShell objects to JSON [Source 4]. Here are the steps to retrieve, modify and save a JSON file:
Open PowerShell.
Use the Get-Content cmdlet to retrieve the content of the JSON file and store it in a variable.
$jsonString = Get-Content -Path "path/to/file.json"
Note: -Raw can be added at the end to have it as a single string instead of array of strings
$jsonObject = ConvertFrom-JSON $jsonString
or
$jsonObject = $jsonString | ConvertFrom-Json
$jsonObject.SystemName = "NewSystemName"
$jsonObject | Add-Member -Name "PSVersion" -MemberType NoteProperty -Value "7.0"
$newJson = $jsonObject | ConvertTo-JSON
Note: -Depth x, where x is a int, can be added at the end to specify how many levels deep the conversion should go.
Can be useful for complex object with nested property
Set-Content -Path "path/to/file.json" -Value $newJson