title: Manipulate JSON File with multiple objects using Powershell
body: <p>I have a JSON File called index.json which looks like this :</p>
  <pre><code>{ 
    &quot;First&quot;: {
      &quot;href&quot;: &quot;test/one two three.html&quot;,
      &quot;title&quot;: &quot;title one&quot;
    },
  
    &quot;Second&quot;: {
      &quot;href&quot;: &quot;test/test test/one two three four.html&quot;,
      &quot;title&quot;: &quot;title two&quot;
      
    }
  }
  </code></pre>
  <p>I want to write a powershell script to update the href of each object to replace the spaces with -.</p>
  <p>The JSON file should looks like this:</p>
  <pre><code>{ 
    &quot;First&quot;: {
      &quot;href&quot;: &quot;test/one-two-three.html&quot;,
      &quot;title&quot;: &quot;title one&quot;
    },
  
    &quot;Second&quot;: {
      &quot;href&quot;: &quot;test/test-test/one-two-three-four.html&quot;,
      &quot;title&quot;: &quot;title two&quot;
      
    }
  }
  </code></pre>
  <p>I got some help from this post:
  <a href="https://stackoverflow.com/questions/33520699/iterating-through-a-json-file-powershell">Iterating through a JSON file PowerShell</a></p>
  <p>I have already written a script to get all the href values, I dont know how to update the same in the original JSON file. My script looks like this:</p>
  <pre><code>function Get-ObjectMembers {
      [CmdletBinding()]
      Param(
          [Parameter(Mandatory=$True, ValueFromPipeline=$True)]
          [PSCustomObject]$obj
      )
      $obj | Get-Member -MemberType NoteProperty | ForEach-Object {
          $key = $_.Name
  
          [PSCustomObject]@{Key = $key; Value = $obj.&quot;$key&quot;}
      }
  }
  
  $a = Get-Content 'index.json' -raw | ConvertFrom-Json | Get-ObjectMembers 
  
  
  foreach($i in $a){
  $i.Value.href.Replace(&quot; &quot;,&quot;-&quot;)
  } 
  </code></pre>