I\'m trying to create a JSON-serialized array. When that array contains only one item I get a string, not an array of strings (in JSON).
Multiple Items (works as exp
I faced this issue with an array that was a child in an object. The array had one object in it, and ConvertTo-Json
was removing the object in the array.
Two things to resolve this:
I had to set the -Depth
parameter on ConvertTo-Json
$output = $body | ConvertTo-Json -Depth 10
I had to create the object in the array as a hashtable and then convert that to an object
$myArray.Add([pscustomobject]@{prop1 = ""; prop2 = "" })