title: Combine JSON objects in PowerShell
body: <p>I have two JSON objects and I am trying to build one object out of it. I am using an example here, but the properties/names are dynamic. </p>
  
  <p>I have looked into <a href="https://stackoverflow.com/a/45483110/1701026">JOIN</a> function, <a href="https://stackoverflow.com/questions/45549909/merge-two-json-objects?noredirect=1&amp;lq=1">MERGE</a>, <a href="http://powershelldistrict.com/how-to-combine-powershell-objects/" rel="nofollow noreferrer">Combine-Object</a> none of them seems to do what I want. As they either replace the values with the one or give me random results. </p>
  
  <p>This is my example,</p>
  
  <pre><code>$aVar = '{ "oldEmployees" : [ { "firstName": "Jane", "lastName": "Doe" }, { "firstName": "John", "lastName": "Doe" } ] }'
  $bVar = '{ "newEmployees" : [ { "firstName": "Joe", "lastName": "Doe" } ] }'
  </code></pre>
  
  <p>I would like to have one JSON as,</p>
  
  <pre><code>{
      "oldEmployees": [
          {
              "firstName": "Jane",
              "lastName": "Doe"
          }, 
          {
              "firstName": "John",
              "lastName": "Doe"
          }
      ],
      "newEmployees": [
          {
              "firstName": "Joe",
              "lastName": "Doe"
          }
      ]
  }
  </code></pre>
  
  <p><strong>BACKGROUND</strong>: I am using a JSON object to deploy multiple resources in Azure DevOps pipeline using an ARM template. I have hit a point where I am limited to use Powershell script to combine multiple variables due to the size limit on the Azure Pipeline Variables to a max of 4K characters. </p>