Skip to content

ConvertTo-JSON: Nested Object of type Newtonsoft.Json.Linq.JObject not converted to Json properly #4996

@amanarneja

Description

@amanarneja

Used the following Azure PS commands and discovered that a Nested JObject is just being converted to an Array instead of an Object.
In the repro steps the type of $result.Outputs.mediaServiceFullInfo.Value is of type Newtonsoft.Json.Linq.JObject as you can see in the final JSON Value doesn't have the Key and Values and has a Square Bracket around it.
$result.Outputs.mediaServiceFullInfo.Value.ToString() does output the Json Snippet under Value correctly.

Steps to reproduce

[Update] : Simplified repro steps in the comments.

$resourceGroupName = 'ExampleResourceGroup'
New-AzureRmResourceGroup -Name $resourceGroupName -Location 'Central US' -Verbose -Force
$result = New-AzureRmResourceGroupDeployment -Name ExampleDeployment -ResourceGroupName $resourceGroupName `
  -TemplateUri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/media-service-output-primary-key/azuredeploy.json

$result.Outputs | ConvertTo-Json

Expected behavior

{
"mediaServiceFullInfo": {
"type": "Object",
"value": {
"primaryAuthEndpoint": "https://wamsprodglobal001acs.accesscontrol.windows.net/",
"secondaryAuthEndpoint": "https://wamsprodglobal002acs.accesscontrol.windows.net/",
"scope": "urn:windowsazuremediaservices"
}
},
"mediaServicePrimaryKey": {
"type": "String",
}
}

Actual behavior

`{
"mediaServiceFullInfo": {
"Type": "Object",
"Value": [
"https://wamsprodglobal001acs.accesscontrol.windows.net/",
"https://wamsprodglobal002acs.accesscontrol.windows.net/",
"urn:windowsazuremediaservices"
]
},
"mediaServicePrimaryKey": {
"Type": "String",
}
}

Environment data

PS C:\WINDOWS\system32> $PSVersionTable

Name Value


PSVersion 5.1.16299.15
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.16299.15
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

Metadata

Metadata

Assignees

Labels

Resolution-FixedThe issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions