Specifying output format for JSON

When output is in the JSON format, you can configure single elements to always be an Array or Object per your business needs.

You cannot update this option at run time. You must rebuild and redeploy the EAR if you make any changes.

The single elements that start with the tag name of the parent element are output as Arrays and others are output as Objects. For example,
  • XPath: OrderList/Order - Single element of Order is always output as a JSON Array.
  • XPath: Activities/Activity - Single element of Activity is output as a JSON Object.

You can use this utility for scenarios that have a different criteria or business need.

Steps to configure the output format for JSON

  1. Add the xapiRest_jsonXPathTransformations.xml file in the runtime/extensions/global/template/resource folder that contains details about elements to be configured as always an Array or an Object.
    Note: You must provide the complete XPath of the element that you want to set as an Array or an Object. For example, to configure the Adjustment element in Order.OrderLines.OrderLine.LineAdjustments.Adjustment to always be an Array, use the XPath as Order/OrderLines/OrderLine/LineAdjustments/Adjustment.
    Sample XML file:
    <JSONTransformations>
         <Transformation Type="ForceToObject" XPath="AllocationRuleList/AllocationRule"  />
         <Transformation Type="ForceToArray" XPath="Activities/Activity"  />
    </JSONTransformations>
    

    The xapiRest_jsonXPathTransformations.xml.sample sample file is provided under the runtime/resource folder.

  2. Rebuild the EAR and deploy.