API Connect

API Connect

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Extraction, validation, and mapping of an Array/JSON field to an XML tag.

  • 1.  Extraction, validation, and mapping of an Array/JSON field to an XML tag.

    Posted Thu May 15, 2025 11:54 AM

    Hello team.
    I'm having trouble capturing a field from an array within a request message in JSON format, capturing the character in the first position of the string, validating it, and mapping it to an XML field (this is the format recognized by the backend).
    I have code in a gatewayScript that obtains the request body, validates the array, extracts the string from the desired field, extracts the first character from the string, validates it, and captures it in a context variable. However, when invoking that context variable in the map node, I'm unable to send the output.
    I've used different ways to invoke the variable containing the data, such as:
    $(fieldValue);
    $(request.body.fieldValue);
    I've also tried directly accessing the desired field as follows:
    $(request.body.documents[0].buyer[0].code);
    $(request.body.documents[0].buyer?.code);
    I've attached the request JSON and XML.
    The JSON input message field is the first "code" of the first "buyer" object.
    After harmonizing it, it should be mapped to the unique "country" tag in the XML.
    I greatly appreciate your suggestions.



    ------------------------------
    Jimmy Perilla
    ------------------------------

    Attachment(s)



  • 2.  RE: Extraction, validation, and mapping of an Array/JSON field to an XML tag.

    Posted Thu May 15, 2025 06:21 PM

    Can you post the mapping code? 

    I think you may need to set it as $(context.ctx.originCountry) as described here (The Map policy structure - IBM Documentation)



    ------------------------------
    Brendon Stephens
    ------------------------------