Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a valid empty JSON array with PowerShell?

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 [].

like image 805
Peter Aron Zentai Avatar asked May 10 '14 13:05

Peter Aron Zentai


1 Answers

It works without pipelining

PS C:\> ConvertTo-Json @()
[

]
like image 153
ДМИТРИЙ МАЛИКОВ Avatar answered Sep 30 '22 13:09

ДМИТРИЙ МАЛИКОВ