36 lines
983 B
PowerShell
36 lines
983 B
PowerShell
|
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
|
||
|
}
|