1
votes

From WSO2 ESB 4.8 - json is supported natively, information can be found in WSO2 websit. Referring below blog w.r.t.json formatter & builder

http://charithaka.blogspot.co.uk/2013/10/the-difference-between-json-streaming.html

My use-case is to use JSON format over HTTP/1.1 REST, main point to note here is:

  • not to tranform the json data within ESB (keep the json format natively within ESB)
  • manipulate the json using mediator in json format (mediator which support json natively - script/custom mediators)

trying to use :

org.apache.axis2.json.JSONStreamBuilder
org.apache.axis2.json.JSONStreamFormatter

as mentioned in Charitha blog. Now, I am not seeing json being converted to soap in the soap message (using Log Mediator).

does that mean, WSO2 ESB 4.8 does not convert a json request to soap under the hood avoiding data loss for some data format (e.g., Array, etc., as mentioned in https://github.com/erny/jsonbuilderformatter)

Can anyone share me an example of logging / manipulating json message using org.apache.axis2.json.JSONStreamBuilder & org.apache.axis2.json.JSONStreamFormatter (or) any other builder and formatter for json without converting into soap message in the message context.

1
useful information in the below link: org.apache.synapse.commons.json.JsonStreamBuilder/JsonStreamFormatter docs.wso2.org/display/ESB480/…Balaji Sengeni

1 Answers

1
votes

As mentioned in http://docs.wso2.org/display/ESB480/JSON+Support doc, from ESB 4.8 onwards you have to use following builder and formatter to keep the JSON representation intact without converting to XML. These two are the default option in ESB 4.8

org.apache.synapse.commons.json.JsonStreamBuilder    
org.apache.synapse.commons.json.JsonStreamFormatter

To log as JSON use,

<log>
    <property name="JSON-Payload" expression="json-eval($.)"/>
</log>

You can manipulate the JSON body using Payload Factory or Script mediators. For e.g.-

<payloadFactory media-type="json">
        <format>
                {
                    "location_response" : {
                        "name" : "$1",
                        "tags" : $2
                    }
                }
        </format>
    <args>
        <arg evaluator="json" expression="$.name"/>
        <arg evaluator="json" expression="$.types"/>
    </args>
</payloadFactory>

Refer the documentation for more details.