Add '-AsArray' parameter to 'ConvertoTo-Json' command (#6438)

Add `-AsArray` parameter to `ConvertoTo-Json` command to always pack the output string in array brackets, even if the input is a single object.
This commit is contained in:
Klaudia Algiz authored and Dongbo Wang committed 2018-03-23 10:32:13 -07:00
1 parent cc3ffd8349
commit dfa11d7f5e
2 files changed
+24 -2

No files matched your search

@@ -35,4 +35,17 @@ Describe 'ConvertTo-Json' -tags "CI" {
$ps.InvocationStateInfo.State | Should -BeExactly "Stopped"
$ps.Dispose()
}
It "The result string is packed in an array symbols when AsArray parameter is used." {
$output = 1 | ConvertTo-Json -AsArray
$output | Should -BeLike "``[*1*]"
$output = 1,2 | ConvertTo-Json -AsArray
$output | Should -BeLike "``[*1*2*]"
}
It "The result string is not packed in the array symbols when there is only one input object and AsArray parameter is not used." {
$output = 1 | ConvertTo-Json
$output | Should -BeExactly '1'
}
}