mirror of
https://github.com/ScoopInstaller/Scoop.git
synced 2025-12-12 02:56:03 +00:00
Normalize multi-line strings to string arrays on format (#2444)
This commit is contained in:
committed by
Richard Kuhnt
parent
2d546d6fe1
commit
f011f249e1
25
lib/json.ps1
25
lib/json.ps1
@@ -9,6 +9,9 @@ Function ConvertToPrettyJson {
|
||||
)
|
||||
|
||||
Process {
|
||||
$data = normalize_values $data
|
||||
|
||||
# convert to string
|
||||
[String]$json = $data | ConvertTo-Json -Depth 8 -Compress
|
||||
[String]$output = ""
|
||||
|
||||
@@ -132,3 +135,25 @@ function json_path_legacy([String] $json, [String] $jsonpath, [String] $basename
|
||||
}
|
||||
return $result
|
||||
}
|
||||
|
||||
function normalize_values([psobject] $json) {
|
||||
# Iterate Through Manifest Properties
|
||||
$json.PSObject.Properties | ForEach-Object {
|
||||
|
||||
# Process String Values
|
||||
if ($_.Value -is [string]) {
|
||||
|
||||
# Split on new lines
|
||||
[array] $parts = ($_.Value -split '\r?\n').Trim()
|
||||
|
||||
# Replace with string array if result is multiple lines
|
||||
if ($parts.Count -gt 1) {
|
||||
$_.Value = $parts
|
||||
}
|
||||
}
|
||||
|
||||
# Process other values as needed...
|
||||
}
|
||||
|
||||
return $json
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user