I am trying to manipulate JSON object that has an array nested. The following PowerShell commands:
@{testArray=@(1,2)} | ConvertTo-Json -Compress
@{testArray=@(@{prop1=1})} | ConvertTo-Json -Compress
@{testArray=@(@{prop1=@(1,2)})} | ConvertTo-Json -Compress
Produce the following output:
{"testArray":[1,2]}
{"testArray":[{"prop1":1}]}
{"testArray":[{"prop1":"1 2"}]}
The first two do what I would expect but the last one doesn't. I would expect output:
{"testArray":[{"prop1":[1,2]}]}
What am I missing here? Using PowerShell 5.1