Converting arrays to JSON string in PowerShell couldn't be more simple:
@(1,2,3) | ConvertTo-Json
Produces:
[
1,
2,
3
]
However if the array is empty the result is an empty string:
@() | ConvertTo-Json
Results an empty string instead of []
.
It works without pipelining
PS C:\> ConvertTo-Json @()
[
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With