Layer7 API Management

Expand all | Collapse all

I have json request, I need to convert this to XML, do some mapping of the parameters and then forward to API. Same way, for response from API, I need to map it, convert back to JSON and share to front end.

Jump to Best Answer
  • 1.  I have json request, I need to convert this to XML, do some mapping of the parameters and then forward to API. Same way, for response from API, I need to map it, convert back to JSON and share to front end.

    Posted 09-08-2016 02:58 PM

    I have json request, I need to convert this to XML, do some mapping of the parameters and then forward to API. Same way, for response from API, I need to map it, convert back to JSON and share to front end.



  • 2.  Re: I have json request, I need to convert this to XML, do some mapping of the parameters and then forward to API. Same way, for response from API, I need to map it, convert back to JSON and share to front end.
    Best Answer

    Posted 09-08-2016 07:54 PM

    Hi,

    Apply JSON Transformation Assertion should be the one can help, please refer to,

    Apply JSON Transformation Assertion - CA API Gateway - 9.1 - CA Technologies Documentation 

     

    Regards,

    Mark



  • 3.  Re: I have json request, I need to convert this to XML, do some mapping of the parameters and then forward to API. Same way, for response from API, I need to map it, convert back to JSON and share to front end.

    Posted 09-09-2016 12:24 PM

    Ok. I used Route via HTTP to get response from an API. I got response as XML. Let suppose we have a element <a> is response. Now, I need to have a xml with element<b> and value of element <b> should have same as <a> and add one more element c with hard code value as hello.

     

    So,

    <a>9999</a>

    needs to be converted as

    <b>9999</b>

    <c>hello</c>

     

    How to get element name change, map value from earlier element and add one more new element in xml.

    We can add/delete element but how to get value mapped from earlier element?

     

    Quick response is appreciable...

     

    Also, when we add element in xml, how can we add value of that element. As, i added <c> but how to add value "hello"



  • 4.  Re: I have json request, I need to convert this to XML, do some mapping of the parameters and then forward to API. Same way, for response from API, I need to map it, convert back to JSON and share to front end.

    Posted 09-09-2016 03:09 PM

    Hello,

    TO get the value of existing element you would use evaluate xpath assertion to retrieve the element then use its output via the .result variable that gets defined and set that to new element.

     

    To add new element with value include full xml element syntax such as <c>some value</c>



  • 5.  Re: I have json request, I need to convert this to XML, do some mapping of the parameters and then forward to API. Same way, for response from API, I need to map it, convert back to JSON and share to front end.

    Posted 09-12-2016 08:08 PM

    Hello,

    steba03 provided a good solution. 

    For more complicate mapping,  you can use Apply XSL Transformation assertion, or Evaluate Regular Expression assertion.

     

    Regards,

    Mark