mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 12:45:47 +00:00
Support $null for convertto-json (#10947)
ConvertTo-Json doesn't allow $null to be passed in even though it can be valid resulting json. Fix is to remove the check that the input is not null. NewtonSoft.Json handles it just fine.
This commit is contained in:
1 parent
6882ad56fd
commit
70ab772da7
3 files changed
+19
-4
No files matched your search
@@ -106,6 +106,17 @@ Describe 'ConvertFrom-Json Unit Tests' -tags "CI" {
|
||||
{ $nestedJson | ConvertFrom-Json -AsHashtable:$AsHashtable } |
|
||||
Should -Throw -ErrorId "System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand"
|
||||
}
|
||||
|
||||
It 'Can convert null' {
|
||||
'null' | ConvertFrom-Json | Should -Be $null
|
||||
$out = '[1, null, 2]' | ConvertFrom-Json
|
||||
$out.Length | Should -Be 3
|
||||
|
||||
# can't compare directly to array as Pester doesn't handle the $null
|
||||
$out[0] | Should -Be 1
|
||||
$out[1] | Should -Be $null
|
||||
$out[2] | Should -Be 2
|
||||
}
|
||||
}
|
||||
|
||||
Describe 'ConvertFrom-Json -Depth Tests' -tags "Feature" {
|
||||
|
||||
@@ -62,4 +62,11 @@ Describe 'ConvertTo-Json' -tags "CI" {
|
||||
|
||||
@{ 'abc' = "'def'" } | ConvertTo-Json @params | Should -BeExactly $expected
|
||||
}
|
||||
|
||||
It "Should handle null" {
|
||||
[pscustomobject] @{ prop=$null } | ConvertTo-Json -Compress | Should -BeExactly '{"prop":null}'
|
||||
$null | ConvertTo-Json -Compress | Should -Be 'null'
|
||||
ConvertTo-Json -Compress $null | Should -Be 'null'
|
||||
1, $null, 2 | ConvertTo-Json -Compress | Should -Be '[1,null,2]'
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user