mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add Jobject serialization support to ConvertTo-Json (#5141)
This commit is contained in:
committed by
Travis Plunk
parent
ed499ced53
commit
36b600d1ec
+4
@@ -426,6 +426,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
rv = obj;
|
||||
}
|
||||
else if (obj is Newtonsoft.Json.Linq.JObject jObject)
|
||||
{
|
||||
rv = jObject.ToObject<Dictionary<object,object>>();
|
||||
}
|
||||
else
|
||||
{
|
||||
TypeInfo t = obj.GetType().GetTypeInfo();
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
Describe 'ConvertTo-Json' -tags "CI" {
|
||||
It 'Newtonsoft.Json.Linq.Jproperty should be converted to Json properly' {
|
||||
$EgJObject = New-Object -TypeName Newtonsoft.Json.Linq.JObject
|
||||
$EgJObject.Add("TestValue1", "123456")
|
||||
$EgJObject.Add("TestValue2", "78910")
|
||||
$EgJObject.Add("TestValue3", "99999")
|
||||
$dict = @{}
|
||||
$dict.Add('JObject', $EgJObject)
|
||||
$dict.Add('StrObject', 'This is a string Object')
|
||||
$properties = @{'DictObject' = $dict; 'RandomString' = 'A quick brown fox jumped over the lazy dog'}
|
||||
$object = New-Object -TypeName psobject -Property $properties
|
||||
$jsonFormat = ConvertTo-Json -InputObject $object
|
||||
$jsonFormat | Should Match '"TestValue1": 123456'
|
||||
$jsonFormat | Should Match '"TestValue2": 78910'
|
||||
$jsonFormat | Should Match '"TestValue3": 99999'
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user