Formatting the API response

,

How can I format the response we get from an api? and can I change it from JSON to XML if required ?

3 Likes

Why API Response formatting is required? Where you want convert JSON to XML. Please explain.

1 Like

in some cases we get the list of states in form of a simple array but to use it in Vflow we need a array of objects. so can i format it so i get code and value array of object as the end response.
api response:

['up','bihar', 'jharkhand']

after formatting;

[{
"code":"1",
"value":"UP"
},{
"code":"1",
"value":"bihar"
},{
"code":"1",
"value":"jharkhand"
}]
6 Likes

@Abhinav_mehta.
Please follow below step:

  1. Create Your Service through vConnect API Management Module (IGW).
  2. Now create and attach an output template to that API.

Output template Sample:

<#assign count = 0>
[
<#list stateList as state>
    {
"code":"${count}",
"value":"${state}"        
}
<#sep>,</#sep>
<#assign count = count + 1>
</#list>
]
5 Likes

@naveen.gupta thanks for the answer

4 Likes