I have been facing an issue while setting a variable in azure policy.
What I have to do is to set currency based on the responses from the backend
response I (status 200) { "currency" : "usd", "amount" : 500 }
Response II (status 200) { "status" :"no data available" }
What I tried:
<set-variable name="currency" value="@((string)(context.Response.Body.As<Jobject>(preserveContent:true).["currency"]))"/>
<set-variable name="currency" value="@((string)(context.Response.Body.As<Jobject>(preserveContent:true).selectToken ("currency"))"/>
<set-variable name="currency" value="@((string)(context.Response.Body.As<Jobject>(preserveContent:true).selectToken ("currency"))"/>
<set-variable name="currency" value="@((string)(context.Response.Body.As<Jobject>(preserveContent:true).GetValueOrDefault<string>.["currency"]))"/>
All of them results in error in case of Response II
What would be the right way to handle if it does not exists?