Skip to content

Conversation

@MrBach69
Copy link

Pull Request: Fix sort_plugin_lists.ps1 script

Summary
Fix ConvertTo-Json depth issue that would corrupt plugin data when running the sort script.
The current script uses ConvertTo-Json without specifying -Depth. PowerShell defaults to depth 2, but the plugin objects in the JSON files are at depth 3. This causes plugin properties to be truncated to type names like System.Object[] instead of their actual values.
Changes

  1. Added -Depth 10 to ConvertTo-Json to preserve all nested data
  2. Added -Raw to Get-Content for more reliable JSON parsing
  3. Removed redundant file write operation (was writing twice)

Before::

$a = Get-Content $file | ConvertFrom-Json
$a.'npp-plugins' = $a.'npp-plugins' | sort -Property 'display-name'
$a | ConvertTo-Json > $file
$content = [IO.File]::ReadAllText($file)
$content = $content -replace ' {2}', "`t"
[IO.File]::WriteAllText($file, $content)

After

$a = Get-Content $file -Raw | ConvertFrom-Json
$a.'npp-plugins' = $a.'npp-plugins' | Sort-Object -Property 'display-name'
$content = $a | ConvertTo-Json -Depth 10
$content = $content -replace ' {2}', "`t"
[IO.File]::WriteAllText($file, $content)

--Testing--
Verified that the JSON structure (max depth 4) is fully preserved after sorting.

@chcg
Copy link
Contributor

chcg commented Jan 29, 2026

@MrBach69 I don't observe that with Powershell 7.5.4. With which version of the Powershell did it happen in your case or did you us Windows Powershell ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants