0

I’m using powershell to update my appsettings.json. I have an array, which I want to replace in the property of my appsettings.json for it. Here are the steps I follow:

  1. get an array of values (done),
  2. transform the appsettings into a powershell object (done),
  3. compare if the values of 1 and the property inside of the appsettings are similar (done),
  4. if different, I want to replace the part in appsettings with my values from 1. This is the part I’m having issues with.

My appsettings looks like this (below). My intention is to replace stuff and stuff2 with values from 1

{
“Key1” : “value1”,
“Key2” : [
 “Stuff”,
 “Stuff2”
]
}

Thank you for your help

1
  • 3
    Please add code that shows what you've tried so far. Commented Dec 17, 2020 at 16:24

1 Answer 1

1

PowerShell allows us to manipulate json objects the same way we would manipulate any other object.
So the following would work

$array = "Stuff3", "Stuff4"
$json = Get-Content .\appsettings.json | ConvertFrom-Json
$json.Key2 = $array
$json | ConvertTo-Json | Set-Content .\appsettings.json
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.