Azure API policy JSON conversion while returning the response from cache

I am using below policy code and storing the data in the cache. While storing as string, it is working fine but requirement is to store in JSON format and its failing and throwing error during conversion .

        <base />
        <set-variable name="cacheKey" value="@(context.Request.MatchedParameters["flightno"])" />
        <cache-lookup-value key="@((string)context.Variables["cacheKey"])" variable-name="cachedResponseValue" />
        <set-variable name="FinalResponse" value="@((JObject)context.Variables["cachedResponseValue"])" />
            <when condition="@(context.Variables.ContainsKey("cachedResponseValue"))">
                <!-- If found in cache then get it from the cache and retun -->
        <base />
        <base />
        <set-variable name="responseValue" value="@(context.Response.Body.As<JObject>(preserveContent: true))" />
        <!-- Store result in cache -->
        <cache-store-value key="@("" + context.Variables["cacheKey"])" value="@((JObject)context.Variables["responseValue"])" duration="30" />
        <base />

I'm able to store the payload as json in the cache, while retrieving,I want to return json and trying to parse it. Error am getting while parsing the response in tag for below syntax as


Error in element 'set-body' on line 22, column 22: Expression return type 'Newtonsoft.Json.Linq.JObject' is not allowed.

It is working fine, if response data type kept as string like


Do you know how to convert the response body to json?

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum