ps/Modules/Cole.PowerShell.Developer/Private/Get-FlattenedAppsettingJson.ps1

36 lines
983 B
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
function Get-FlattenedAppsettingJson {
param (
[object]$Json
)
if ($null -eq $Json) {
Write-Warning "`$Json -eq `$null"
return $null
}
$logLead = (Get-LogLeadName)
$returnValues = @()
if ($Json.GetType().Name -eq "PSCustomObject") {
$Json = ConvertTo-Hash $Json
}
if ($Json.GetType().Name -match "Hashtable") {
foreach ($key in $Json.Keys) {
$returnValues += (Get-FlattenedAppsettingJsonKeyValue $key $Json[$key])
}
} elseif ($Json -is [System.Collections.IEnumerable] -and $Json -isnot [string]) {
for($i = 0; $i -lt $Json.Count; $i++) {
$item = $Json[$i]
$deepPairs = (Get-FlattenedAppsettingJson $item)
foreach($pair in $deepPairs) {
$returnValues += @{ Key = "$Key`[$i]`:$($pair.Key)"; Value = $pair.Value}
}
}
} else {
# return @{ Value = $Json; }
}
return $returnValues
}