powershell 遍历json_Json文件到powershell并返回到json文件

我试图在power

shell中操作json文件数据并将其写回文件.甚至在操作之前,当我刚刚从文件中读取时,将它转换为powershell中的Json对象并将其写回文件,某些字符将被某些代码替换.以下是我的代码:

$jsonFileData = Get-Content $jsonFileLocation

$jsonObject = $jsonFileData | ConvertFrom-Json

... (Modify jsonObject) # Commented out this code to write back the same object

$jsonFileDataToWrite = $jsonObject | ConvertTo-Json

$jsonFileDataToWrite | Out-File $jsonFileLocation

某些字符正在被其代码替换.例如.:

< is replaced by <

> is replaced by >.

' is replaced by \u0027

样本输入:

{

"$schema": "https://source.com/template.json#",

"contentVersion": "1.0.0.0",

"parameters": {

"accountName": {

"type": "string",

"defaultValue": ""

},

"accountType": {

"type": "string",

"defaultValue": ""

},

},

"variables": {

"location": "sampleLocation",

"account": "[parameters('accountName')]",

"type": "[parameters('accountType')]",

}

}

输出:

{

"$schema": "https://source.com/template.json#",

"contentVersion": "1.0.0.0",

"parameters": {

"accountName": {

"type": "string",

"defaultValue": "

" }, "accountType": { "type": "string", "defaultValue": "

" }, }, "variables": { "location": "sampleLocation", "account": "[parameters(\u0027accountName\u0027)]", "type": "[parameters(\u0027accountType\u0027)]", } }

为什么会发生这种情况,我该怎么做才能让它不是替换字符并以同样的方式写回来?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值