title: Condition to check context.Request.Body is JArray or JObject in azure api management policy
body: <p>I am using Azure API Management policy expression to send the Supplier value into each post, put and delete request to backend API. I wrote a code which was working fine when the request type of JObject. but I have some case where the request can be type of JArray, in that case it throw 500 error. The below snippet is working fine for JObject.</p>
  <pre><code>    &lt;set-variable name=&quot;Supplier&quot; value=&quot;DummySupplier&quot; /&gt;
      &lt;choose&gt;
          &lt;when condition=&quot;@(new [] {&quot;post&quot;, &quot;put&quot;, &quot;delete&quot;}.Contains(context.Request.Method, StringComparer.OrdinalIgnoreCase))&quot;&gt;
              &lt;set-body&gt;@{ 
                           JObject body = context.Request.Body.As&lt;JObject&gt;(); 
                           body.Add(new JProperty(&quot;Supplier&quot;, ((string)context.Variables[&quot;Supplier&quot;])));
                           return body.ToString(); 
                        }
              &lt;/set-body&gt;
          &lt;/when&gt;
      &lt;/choose&gt;
  </code></pre>
  <p>I need a condition where I can check the request body type and parse accordingly. Otherwise in case of if request body is IEnumerable/JArray type, then above code gives me error.</p>
  <p>Getting below error when I have an <code>IEnumerable</code> in request body</p>
  <blockquote>
  <p>The message body is not a valid JSON. Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.</p>
  <p>at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)<br />
  at Microsoft.WindowsAzure.ApiManagement.Proxy.Gateway.MessageBody.AsJObject(Stream stream, Encoding encoding, JsonSerializerSettings settings)<br />
  at Microsoft.WindowsAzure.ApiManagement.Proxy.Gateway.MessageBody.As[T](Boolean preserveContent)</p>
  </blockquote>
  <p>Could you please help me out with this?</p>