Utility/ConvertTo-BPAJson.ps1

function ConvertTo-BPAJson {
    <#
        .SYNOPSIS
            Converts a BPA object into JSON.
 
        .DESCRIPTION
            ConvertTo-BPAJson converts a BPA object to JSON, and changes the name of the ___type parameter to __type.
 
        .PARAMETER InputObject
            Specifies the objects to convert to JSON format.
 
        .PARAMETER Depth
            Specifies how many levels of contained objects are included in the JSON representation. The default value is 5.
 
        .PARAMETER Compress
            Omits white space and indented formatting in the output string.
 
        .INPUTS
            All BPA object types can be converted by this function.
 
        .EXAMPLE
            # Change notes for a workflow
            $w = Get-BPAWorkflow "Some Workflow"
            ConvertTo-BPAJson -InputObject $w
 
        .NOTES
            Author(s): : David Seibel
            Contributor(s) :
            Date Created : 07/10/2017
            Date Modified : 02/09/2018
 
        .LINK
            https://github.com/davidseibel/PoshBPA
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true, Position = 0)]
        [ValidateNotNullOrEmpty()]
        $InputObject,

        [ValidateNotNullOrEmpty()]
        [int]$Depth = 5,

        [ValidateNotNullOrEmpty()]
        [switch]$Compress = $true
    )

    $InputObject.PSObject.Properties.Remove("BPAServer")
    $InputObject.PSObject.Properties.Remove("TypeName")
    $InputObject.PSObject.Properties.Remove("MatchedProperty")
    $json = ConvertTo-Json -InputObject $InputObject -Depth $Depth -Compress:$Compress
    $json = $json.Replace("___type", "__type")

    return $json
}