I have a list of property names and values that looks like this:
[string[]]$PropertyNames = 'name', 'priority', 'levelStr', 'escalatingChainId', 'supressAlertClear', 'deviceGroups'
[string[]]$PropertyValues = 'Test', '19665999', 'Warn', '3', 'false', 'TestGroup,TestGroup2'
I am trying to turn it into JSON where whatever value is associated with deviceGroups, should be considered an array;
Foreach ($property in $PropertyNames) {
Switch ($property) {
{$_ -in ("deviceGroups", "devices")} {
$propertyData.Add($_, @($($PropertyValues[$index])))
$index++
}
default {
$propertyData.Add($_, $($PropertyValues[$index]))
$index++
}
}
}
This generates JSON that looks like this:
{
"name": "Test",
"priority": "19665999",
"levelStr": "Warn",
"escalatingChainId": 3
"supressAlertClear": "false"
"deviceGroups": [
"TestGroup, TestGroup2"
],
]
}
That's no good, because TestGroup and TestGroup2 should be on separate lines (since that is supposed to be a JSON array). How do I turn these strings into valid JSON (where deviceGroups key/value (which could be comma-separated) must be an array)?