I have a script that updates a configuration file with current year, but for some reason the copyright symbol is not being inserted correctly. The PowerShell script is UTF-8 with BOM and the JSON file is UTF-8.
The workflow is that I read from a JSON file, update the copyright date, and then save to a JSON file again.
The JSON file info.json
:
{
"CopyrightInfo": "Copyright © CompanyName 1992"
}
Reproducible excerpt of the PowerShell script:
$path = "./info.json"
$a = Get-Content $path| ConvertFrom-Json
$a.'CopyrightInfo' = "Copyright $([char]::ConvertFromUtf32(0x000000A9)) CompanyName $((Get-Date).Year)"
$a | ConvertTo-Json | set-content $path
I've tried a bunch of ways, above is the latest attempt. It looks fine when printed in PowerShell or opened in Notepad, but any other editor (Visual Studio Code, SourceTree, Azure DevOps file viewer, etc) they always result in the following:
"CopyrightInfo": "Copyright � CompanyName 2022"
If anyone can explain what I'm doing wrong that would great and even greater if they could also add a way to make it work properly.
I'm using PowerShell version 5.1.19041.1682
EDIT: Updated issue with reproducible code excerpts and used PowerShell version.