I want to change content of JSON file from a bat file. I thought doing that by calling powershell and use a single-line pipeline command.
Here I am so far:
Get-Content test.json -raw | ConvertFrom-Json | Set-ItemProperty -Name "ServiceAccess.Host" -Value "localhost:5000" | ConvertTo-Json | Set-Content test.json
Here is my JSON file:
{
"ServiceAccess":
{
"Host": "localhost:3000"
}
}
It does not work:
Set-ItemProperty : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input. At line:1 char:49 + ... From-Json | Set-ItemProperty -Name "ServiceAccess.Host" -Value "local ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (@{ServiceAccess=}:PSObject) [Set-ItemProperty], ParameterBindingExcept ion + FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.SetItemPropertyCommand
What is the proper way to change a JSON object in the powershell pipeline?