Skip to content

Commit 37d4073

Browse files
committed
Sort childs alphabetically
1 parent 802b26f commit 37d4073

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/json.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,20 @@ function Sort-ScoopManifestRootProperties {
253253
$null = Add-Member -InputObject $SortedObject -NotePropertyName $_ -NotePropertyValue $JsonAsObject.$_
254254
}
255255

256+
# Order childs alphabetically if parent key is of type PSCustomObject
257+
foreach (
258+
$Key in $SortedObject.'PSObject'.'Properties'.Where{
259+
$_.'TypeNameOfValue' -eq 'System.Management.Automation.PSCustomObject'
260+
}.'Name'
261+
) {
262+
$ChildKeys = [string[]]($SortedObject.$Key.'PSObject'.'Properties'.'Name' | Sort-Object)
263+
$ChildObject = [PSCustomObject]::new()
264+
$ChildKeys.ForEach{
265+
$null = Add-Member -InputObject $ChildObject -NotePropertyName $_ -NotePropertyValue $SortedObject.$Key.$_
266+
}
267+
$SortedObject.$Key = $ChildObject
268+
}
269+
256270
# Return the sorted object
257271
$SortedObject
258272
}

0 commit comments

Comments
 (0)