8000 Change minimum depth to 0 for `ConvertTo-Json` by kvprasoon · Pull Request #14830 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Change minimum depth to 0 for ConvertTo-Json #14830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2021
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
0