In powershell, the following produces correct results.
$foo = @{}
$foo.bar = @{}
$foo.bar.buzz = @("herp","derp")
ConvertTo-Json $foo
{
"bar": {
"buzz": [
"herp",
"derp"
]
}
}
However if I add one more level, then the array "buzz" is flattened into a string
$foo = @{}
$foo.bar = @{}
$foo.bar.buzz = @{}
$foo.bar.buzz.bazz = @("herp","derp")
ConvertTo-Json $foo
{
"bar": {
"buzz": {
"bazz": "herp derp"
}
}
}
Why does powershell flatten Arrays into strings? This issue feels similar to the following SO questions, but none of the purposed solutions solves it.
why-does-powershell-silently-convert-a-string-array-with-one-item-to-a-string
what-determines-whether-the-powershell-pipeline-will-unroll-a-collection