Merge/Concatenate multiple json files using PowerShell


I have multiple .json files that I would like to concatenate or append to each other using PowerShell. Where one will end, I would like the next to continue. To keep it simple, I’m just going to show an example of two files that I would like to merge.



I know that I can use the below syntax in Powershell to concatenate the two json files.

Get-Content “C:\File1.json”,”C:\File2.json” | Set-Content “C:\CombinedOutput.json”

However, when I execute this script, I nearly get what I need, except the beginning and ending brackets are left (where one json file ends and the next begins). These two brackets as shown in the example below in the middle, which should be removed and replaced with a comma as shown in the above example.

Note: I was unable to bold so I am drawing attention to them by surrounding with asterisks.

To reiterate, these brackets…

…should be replaced with a comma.

The desired output file would then look like the below and even merging several json files into one would still allow it to properly flow like one continuous json file.


This is actually surprisingly easy since they’re both arrays:

PowerShell can concatenate arrays natively here.


Merge/Concatenate multiple json files using PowerShell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply