From 6562d16ce500197b428b51915332c6649df302df Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Sat, 20 Sep 2025 13:30:41 -0700 Subject: [PATCH] Standardizes JSON output: depth, UTF-8, key order - Sorts top-level config keys before serialization for deterministic files and cleaner diffs. - Increases JSON depth to 10 to retain nested settings. - Writes JSON as UTF-8 via Set-Content for consistent encoding. - Applies across config export and UI save flows. --- FFUDevelopment/BuildFFUVM.ps1 | 2 +- FFUDevelopment/BuildFFUVM_UI.ps1 | 5 ++++- FFUDevelopment/FFUUI.Core/FFUUI.Core.Config.psm1 | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/FFUDevelopment/BuildFFUVM.ps1 b/FFUDevelopment/BuildFFUVM.ps1 index 21c94a0..1ba5876 100644 --- a/FFUDevelopment/BuildFFUVM.ps1 +++ b/FFUDevelopment/BuildFFUVM.ps1 @@ -4004,7 +4004,7 @@ function Export-ConfigFile { } # Convert to JSON and save - $orderedParams | ConvertTo-Json | Out-File $ExportConfigFile -Force + $orderedParams | ConvertTo-Json -Depth 10 | Set-Content -Path $ExportConfigFile -Encoding UTF8 } function Get-PEArchitecture { param( diff --git a/FFUDevelopment/BuildFFUVM_UI.ps1 b/FFUDevelopment/BuildFFUVM_UI.ps1 index 182884e..9b4e054 100644 --- a/FFUDevelopment/BuildFFUVM_UI.ps1 +++ b/FFUDevelopment/BuildFFUVM_UI.ps1 @@ -410,7 +410,10 @@ $script:uiState.Controls.btnRun.Add_Click({ } $configFilePath = Join-Path $config.FFUDevelopmentPath "\config\FFUConfig.json" - $config | ConvertTo-Json -Depth 10 | Set-Content -Path $configFilePath -Encoding UTF8 + # Sort top-level keys alphabetically for consistent output + $sortedConfig = [ordered]@{} + foreach ($k in ($config.Keys | Sort-Object)) { $sortedConfig[$k] = $config[$k] } + $sortedConfig | ConvertTo-Json -Depth 10 | Set-Content -Path $configFilePath -Encoding UTF8 $script:uiState.Data.lastConfigFilePath = $configFilePath if ($config.InstallOffice -and $config.OfficeConfigXMLFile) { diff --git a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Config.psm1 b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Config.psm1 index 43a65f6..9a322b7 100644 --- a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Config.psm1 +++ b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Config.psm1 @@ -727,7 +727,10 @@ function Invoke-SaveConfiguration { -DefaultExt ".json" if ($savePath) { - $config | ConvertTo-Json -Depth 10 | Set-Content -Path $savePath -Encoding UTF8 + # Sort top-level keys alphabetically for consistent output + $sortedConfig = [ordered]@{} + foreach ($k in ($config.Keys | Sort-Object)) { $sortedConfig[$k] = $config[$k] } + $sortedConfig | ConvertTo-Json -Depth 10 | Set-Content -Path $savePath -Encoding UTF8 [System.Windows.MessageBox]::Show("Configuration file saved to:`n$savePath", "Success", "OK", "Information") } }