There are some cases we need to update json files using powershell.
This is how I do it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $filePath = "C:\jeevan\sample.json" | |
| $file = ([System.IO.File]::ReadAllText($filePath) | ConvertFrom-Json) | |
| Write-Host $file.property1 | |
| $file.property1 = Get-Random | |
| $file | ConvertTo-Json | Out-File -FilePath $filePath -Encoding utf8 -Force |

I used following json file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "property1": 123, | |
| "property2": "value2" | |
| } |
Done 🙂