Tags

,

If you have come up with the requirement of accessing JSON content from JSON payload within the mediation flow of the Wso2 ESB, You should send the “Content-Type” HTTP header with the request like below.

“Content-Type : application/json”

Then with in the mediation flow of the ESB (within proxy service,sequence,REST API), you can access the JSON payload using JSONPath syntax. See the following example. JSON payload like below

{
  "coordinates":{
     "location":[
        {
           "name":"Bermuda Triangle",
           "n":25.0000,
           "w":71.0000
        },
        {
           "name":"Eiffel Tower",
           "n":48.8582,
           "e":2.2945
        }
     ]
  }
}

If you want to access the “name” field of the first “location” member of the above JSON payload,

You can achieve that using following JSONPath expression.

<log>
<property name="location" expression="json-eval($.coordinates.location[0].name)"></property>
</log>

If you send a request like following

con_type

You can see below log line in the Wso2Carbon logs.

  INFO - LogMediator To: /def, MessageID: urn:uuid:89c8074e-e03f-4e0f-9dc7-c01bc2c3c30c, Direction: request, location = Bermuda Triangle

You can refer document [1],[2] for get more idea about the JSON payload handling in the Wso2 ESB and get an idea about the JSONPath syntax.

[1] – https://docs.wso2.com/display/ESB490/JSON+Support

[2] – http://goessner.net/articles/JsonPath/

 

Advertisements