Joost Kuin
asked on
Cannot resolve variable within JSON file
In the example code below, I'm attempting to set variable varB to the same value as varA.
But when i execute this script, the ouput is:
To be clear, I expected the output to be:
What is the correct syntax to refer to the value of another variable within the same JSON file.
By the way, I based my example on this web page:
https://docs.microsoft.com/en-us/azure/architecture/building-blocks/extending-templates/objects-as-parameters
$strJSONdata = @"
{
"variables": {
"varA": "myVariable",
"varB": "[variables('varA')]"
}
}
"@
$objJSON = $strJSONdata | ConvertFrom-Json
write-host $objJSON.variables.varA
write-host $objJSON.variables.varB
But when i execute this script, the ouput is:
myVariable
[variables('varA')]
To be clear, I expected the output to be:
myVariable
myVariable
What is the correct syntax to refer to the value of another variable within the same JSON file.
By the way, I based my example on this web page:
https://docs.microsoft.com/en-us/azure/architecture/building-blocks/extending-templates/objects-as-parameters
Just because Azure may interpret JSON files formatted a specific way for their templates, doesn't mean it has any relation to PowerShell. PowerShell can read JSON, but essentially all you get is properties (and subproperties) and their values. It doesn't try to interpret the values as anything other than strings (at least to my knowledge).
ASKER
@Footech: Thank you for your reply. So basically there is no native support in JSON for values to refer to another value within a single file?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
although not the answer I was hoping for. At least I can end my search (which was driving me nuts).
@footech: Thanks for your help!
@footech: Thanks for your help!