I have created a mediation example that can be used to address your specific use case.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="enrichProxy"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<property expression="json-eval($)"
name="orderSource"
scope="default"
type="STRING"/>
<log>
<property expression="json-eval($)" name="orderSource"/>
</log>
<call>
<endpoint>
<address uri="http://run.mocky.io/v3/9cf4b844-57c1-4fa5-a101-881dc36385bd"/>
</endpoint>
</call>
<log level="full"/>
<property name="messageType"
scope="axis2"
type="STRING"
value="application/json"/>
<enrich>
<source clone="false" property="orderSource" type="property"/>
<target action="child" xpath="json-eval($)"/>
</enrich>
<payloadFactory media-type="json">
<format>{"request" : $1}</format>
<args>
<arg evaluator="json" expression="$"/>
</args>
</payloadFactory>
<respond/>
</inSequence>
</target>
<description/>
</proxy>
I have chosen to use JSON paths instead of XPATH for better performance in handling JSON payloads during mediation.
The proxy service is invoked with the payload:
{"orderSource":"value"}
We capture this payload using JSON path and store the value in the property mediator orderSource. Then we make an endpoint call which returns the JSON payload:
{"first":"response"}
To incorporate the value of the property mediator into the second payload, we utilize the enrich mediator to achieve the following payload:
{
"first": "response",
"orderSource": "value"
}
To further manipulate the generated payload as a value in another JSON element, a payload factory mediator is used. This results in the following payload after the mediation:
{
"request": {
"first": "response",
"orderSource": "value"
}
}
For more information on JSON Support in WSO2, refer to [1].
Updated
The mediation has been modified to use XPATH functions instead of JSON path. Please refer to the sample configuration below:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="enrichProxy2"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="http,https">
<target>
<inSequence>
<property name="messageType"
scope="axis2"
type="STRING"
value="application/xml"/>
<enrich>
<source clone="true" xpath="$body//jsonObject/*"/>
<target property="orderSource" type="property"/>
</enrich>
<call>
<endpoint>
<address uri="http://run.mocky.io/v3/9cf4b844-57c1-4fa5-a101-881dc36385bd"/>
</endpoint>
</call>
<enrich>
<source clone="false" property="orderSource" type="property"/>
<target action="child" xpath="//jsonObject"/>
</enrich>
<enrich>
<source clone="true" xpath="//jsonObject"/>
<target type="body"/>
</enrich>
<respond/>
</inSequence>
</target>
<description/>
</proxy>
Update 2
To disable automatic data conversion, you can set synapse.commons.json.output.autoPrimitive = false in the synapse.properties file [2].
For more details, refer to the link [2] for insights on JSON handling in WSO2 ESB.