Skip to Content
Technical Articles
Author's profile photo Akanksha sinha

Extract value from plain JSON/JSON array using Extract variable policy

Hello Everyone…..Welcome to my first blog!!!!!!

Introduction-As a beginner in SAP API management ,I have been exploring various policies in SAP API portal . In this blog post ,I have shared Extract variable policy which is used to read and parse information from a request or response and set it to the value of the variables that can be used in API proxy execution.

 Use Cases:-

1.To get access_token using extract variable policy from OAuth2.0 secured proxy API and sending it to another API to have access using service callout policy.


2. Getting response from the target endpoint (post flow) and extracting few fields using extract variable policy. In the given example I am extracting value of mobile no and city.

Consider a scenario , wherein  I am calling an API whose response is in the JSON array format.

Sample response:-

          "mobileno": "123456",
          "postal-address": {
                            "streetno": "11",
                            "city": "New Delhi",


In the above response code, mobile no and postal address  is in the 0 pocket of the array  .To extract this value of mobile no and city ,I will be using extract variable policy in the target end point post flow.


Sample code will be

<ExtractVariables async="true" continueOnError="false" enabled="true" xmlns=''>
<Variable name="mob">
<Variable name="city">




I am using assign message policy in target end point post flow to assign the value of mob and city in the Mobileno and City respectively

<!-- This policy can be used to create or modify the standard HTTP request and response messages -->
<AssignMessage async="false" continueOnError="false" enabled="true" xmlns=''>
<Payload contentType="application/json">{"Mobileno":"{mob}","City":"{city}"}</Payload>
<AssignTo createNew="false" type="response">response</AssignTo>



Conclusion:-In this way ,we can extract elements from JSON array using extract variable policy and assign it to some variable using assign message policy in SAP API management.


That’s it from my side. I hope you have enjoyed learning  this blog. Please let me know your feedback or any query in the comment section. and keep following my profile for similar content.




Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Sumandeep Kaur
      Sumandeep Kaur

      This blog is really helpful Akanksha ..Thanks for sharing it.




      Author's profile photo vinduja N
      vinduja N

      Nice, Thank You Akankshaa