Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ConvertToJsonCommand : PSCmdlet
/// Gets or sets the Depth property.
/// </summary>
[Parameter]
[ValidateRange(1, int.MaxValue)]
[ValidateRange(0, int.MaxValue)]
public int Depth
{
get { return _depth; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,34 @@ Describe 'ConvertTo-Json' -tags "CI" {
$ps.Dispose()
}

It "Should accept minimum depth as 0." {
$ComplexObject = [PSCustomObject] @{
FirstLevel1 = @{
Child1_1 = 0
Bool = $True
}
FirstLevel2 = @{
Child2_1 = 'Child_2_1_Value'
Child2_2 = @{
ChildOfChild2_2= @(1,2,3)
}
Float = 1.2
}
Integer = 10
Bool = $False
}

$ExpectedOutput = '{
"FirstLevel1": "System.Collections.Hashtable",
"FirstLevel2": "System.Collections.Hashtable",
"Integer": 10,
"Bool": false
}'

$output = $ComplexObject | ConvertTo-Json -Depth 0
$output | Should -Be $ExpectedOutput
}

It "The result string is packed in an array symbols when AsArray parameter is used." {
$output = 1 | ConvertTo-Json -AsArray
$output | Should -BeLike "``[*1*]"
Expand Down