Extend JSON with another in PowerShell


Is there some simple way to extend one JSON file with another and save the output to yet another file using PowerShell? Currently I’m attempting to write a recurrent function that will allow me to do that*, but maybe there is a simpler solution out there?

*iterate over properties of a JSON converted to a PSCustomObject and replace them if needed (actually check my answer below)

Edit: I need to do something similar to what jquery.extend does so, my input is:


And my output is supposed to be:

P.S. Generally I need to write a script that can be run from a batch file and does not require 3rd party libraries (is limited to Windows resources). I tried my luck with Cscript JavaScript, but I decided against using it when I found out, that the only built in method to parse JSON is to eval it.


After a lot of trial and error I managed to write my recurrent function.

I have no idea if this is the easiest way to achieve my goal, but it does get the job done. This also doubles as answer to the how to combine\combine\merge two PSCustomObjects, which appears no one has asked yet (maybe I’m breaching open doors here). I’m nearly inclined to rewrite the question as such, but my gut is telling me there might be different methods of extending JSON using PowerShell, which don’t necessarily require converting my JSON files to PSCustomObject.


Extend JSON with another in PowerShell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply