Function Format-JsonOrder {
        Sorts JSON output.
        Reformats a JSON string so the output looks better than what ConvertTo-Json outputs.
        Required: [string] The JSON text to sort.
    .PARAMETER PropertyStartList
        Optional: The list of properties to put at the start of the json object.
    .PARAMETER PropertyEndList
        Optional: The list of properties to put at the end of the json object.
    .PARAMETER OnlyListedProperties
        Optional: Only list the properties that are in the PropertyStartList and PropertyEndList.
    .PARAMETER SortAlphabetically
        Optional: Sort the properties alphabetically.
    .PARAMETER Recursive
        Optional: Sort the properties that are arrays or objects.
        $json | ConvertFrom-Json | Format-JsonOrder -PropertyStartList @('policyType','displayName') -PropertyEndList @('policyRule') -SortAlphabetically
        $json | Format-JsonOrder -PropertyStartList @('policyType','displayName') -PropertyEndList @('policyRule') -SortAlphabetically
        $json | Format-JsonOrder -SortAlphabetically -Recursive

        [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]

        [Parameter(Mandatory = $false)]

        [Parameter(Mandatory = $false)]

        [Parameter(Mandatory = $false)]
        [Parameter(Mandatory = $false)]

        [Parameter(Mandatory = $false)]
        ## Get the name of this function
        [string]${CmdletName} = $PSCmdlet.MyInvocation.MyCommand.Name

        $jsonList = @()

        Foreach($JsonItem in $Json)
            If($Json -is [string]){
                Write-Verbose ("{0} :: Converting json to object..." -f ${CmdletName})
                $JsonObj = ($JsonItem | ConvertFrom-Json)
                Write-Verbose ("{0} :: Using an object..." -f ${CmdletName})
                $JsonObj = $JsonItem
            $Params = @{
                Object = $JsonObj

            If($PropertyStartList.Count -gt 0){
                $Params.PropertyStartList = $PropertyStartList

            If($PropertyEndList.Count -gt 0){
                $Params.PropertyEndList = $PropertyEndList

            If($OnlyListedProperties -eq $true){
                $Params.OnlyListedProperties = $true

            If($SortAlphabetically -eq $true){
                $Params.SortAlphabetically = $true

            If($Recursive -eq $true){
                $Params.Recursive = $true

            $jsonList += ConvertTo-OrderObject @Params
        return $jsonList | ConvertTo-Json -Depth 100

Set-Alias -Name Sort-Json -Value Format-JsonOrder