我正在编写一个脚本来更改JSON文件,但是当文件转换回JSON时,它会扩展特殊字符.
例如,JSON文件包含带有"&"的密码.复制问题的快速方法是使用以下命令:
PS>"密码&123"| Convertto-Json输出为:"Password\u0026123"
##Here is how I import the JSON FILE:
$jsonfile = (Get-Content .\example.json -Encoding Ascii) -join "`n" | ConvertFrom-Json
##Exporting JSON FILE without modifying it.
$jsonfile | ConvertTo-Json |Out-File "new.json"
Run Code Online (Sandbox Code Playgroud)
- 这是一个简化的JSON文件的例子
{
"Server1":
{
"username":"root",
"password":"Password&dfdf"
},
"Server2":
{
"username":"admin",
"password":"Password&1234"
}
}
Run Code Online (Sandbox Code Playgroud)