Merge-Json.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#
# Merge-Json.ps1
#
function Merge-Json {
    <#
    .SYNOPSIS
     Merges input json file into output one
    .DESCRIPTION
     Will rewrite output
    .EXAMPLE
    # Simple use
      New-Merge-Json -InputJson ="in.json" -OutputJson="out.json"
    #>
    
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory=$True)]
        [string]$InputJson,

        [Parameter(Mandatory=$True)]
        [string]$OutputJson

    )

    [TreeWalk.Runner]::Defaults
    [TreeWalk.Runner]::runnerType = "Tree"    
    [TreeWalk.Runner]::outputProcessorType = "Merge"

    $InputFullPath = ""

    if(![System.IO.Path]::IsPathRooted($InputJson)) {
        $InputFullPath = "$Env:BASEPATH\$InputJson"
    } else {
        $InputFullPath = "$InputJson"
    }

    $OutFullPath = ""

    if( ![System.IO.Path]::IsPathRooted($OutputJson) ) {
        $OutFullPath = "$Env:BASEPATH\$OutputJson"
    } else { 
        $OutFullPath = "$OutputJson"
    }

    [TreeWalk.Runner]::Run($InputFullPath,$OutFullPath,"")
     
}