Normalize multi-line strings to string arrays on format (#2444)

This commit is contained in:
Brandon Smith
2018-07-29 07:24:28 -04:00
committed by Richard Kuhnt
parent 2d546d6fe1
commit f011f249e1

View File

@@ -9,6 +9,9 @@ Function ConvertToPrettyJson {
) )
Process { Process {
$data = normalize_values $data
# convert to string
[String]$json = $data | ConvertTo-Json -Depth 8 -Compress [String]$json = $data | ConvertTo-Json -Depth 8 -Compress
[String]$output = "" [String]$output = ""
@@ -132,3 +135,25 @@ function json_path_legacy([String] $json, [String] $jsonpath, [String] $basename
} }
return $result 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
}