ArmDeploymentPropertiesExtended.Outputs does not return valid JSON
See original GitHub issueI’m trying to collect the outputs from an ARM template using the Outputs
property of ArmDeploymentPropertiesExtended
.
For example:
var depop = rg.GetArmDeployments().CreateOrUpdate(Azure.WaitUntil.Completed, "MyDeployment", deploymentContent);
var outputs = depop.Value.Data.Properties.Outputs;
var credentials = outputs.ToObjectFromJson<DeploymentCredentials>();
Where the outputs section of my ARM template contains something like this:
"outputs": {
"username": {
"value": "[list(resourceId('Microsoft.Web/sites/config', variables('function_app_name'), 'publishingcredentials'), '2016-08-01').properties.publishingUserName]",
"type": "string"
},
"password": {
"value": "[list(resourceId('Microsoft.Web/sites/config', variables('function_app_name'), 'publishingcredentials'), '2016-08-01').properties.publishingPassword]",
"type": "string"
}
}
If I inspect the BinaryData
object returned, it appears to contain a username and password that match what I can see in the Azure portal. A promising start. Unfortunately, on closer inspection, the BinaryData
contents is not quite valid JSON:
{
{
"username": {
"type": "String",
"value": "$someValueHere"
},
"password": {
"type": "String",
"value": "AsIfImGoingToShareThaat_DeadBeef_0123456789"
}
}
}
This is almost valid JSON, except for the extra pair of curly braces. This can be checked at (for instance) jsonlint.com, which complains with the following message:
Error: Parse error on line 1:
{ { "username": {
--^
Expecting 'STRING', '}', got '{'
Unfortunately, this is enough to break the JSON deserialiser, so that when we call outputs.ToObjectFromJson<DeploymentCredentials>()
we get an empty instance of our class, without the values from the response.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Hi @Yao725. Thanks for taking a look. Case sensitivity is a good guess, but I think I can rule it out. I’m using
JsonProperty
attributes that match the casing of the raw JSON names. Since I can get it to work (see below) without further tweaks to theJsonSerializerOptions
, I think we can rule this out.I’m pretty sure the problem is that the returned JSON string contains a JSON object nested within another JSON object, without being in an array or having a key. This is not valid per the JSON specification (friendly | RFC) and causes errors in every validator I’ve tried. I actually first noticed this when trying to (lazily) generate the classes with quicktype.
As I said in my 2nd comment above, removing the outer pair of braces makes the JSON valid and allows it to be deserialised. For anyone else who stumbles across this problem, here’s the code I used to fix it:
Hi @tdwright, I tested this method and it worked as expected. One possible reason that you can’t deserialize the outputs might be that
ToObjectFromJson
method has a default JsonSerializerOptions which set thePropertyNameCaseInsensitive
to false. So could you double check if the properties’ name in DeploymentCredentials could match the response in case sensitive or you can try this way to see if the deserialization can work: