【问题标题】:Replace content by key in JSON在 JSON 中按键替换内容
【发布时间】:2019-08-13 20:08:06
【问题描述】:

我的 JSON 文件具有以下结构:

{
    "Url": "placeholder",
}

我想编写一个 Powershell 脚本,用键(“Url”)替换值(“占位符”)。

我知道如何替换内容,因为我不知道如何将内容保存回文件。

$snapshot = (Get-Content settings.json | ConvertFrom-Json)
$snapshot.Url = "Test" 

【问题讨论】:

    标签: json powershell


    【解决方案1】:

    您可以使用Set-Content cmdlet 将其写回。例如:

    $snapshot | ConvertTo-Json | Set-Content
    

    【讨论】:

      猜你喜欢
      • 2017-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-04
      相关资源
      最近更新 更多