The ESB Profile of WSO2 Enterprise Integrator (WSO2 EI) provides support for JavaScript Object Notation (JSON) payloads in messages. The following sections describe how to work with JSON via the ESB Profile of WSO2 EI:
...
Note that we have used the Property mediator to mark the outgoing payload to be formatted as JSON:
...
Info | |||||
---|---|---|---|---|---|
If you need to convert complex XML responses (e.g., XML with with <property name="messageType" value="application/json/badgerfish" scope="axis2" type="STRING"/> You will also need to ensure you register the following message builder and formatter as specified in Message Builders and Formatters.
|
...
Mediator | Usage | |||||
---|---|---|---|---|---|---|
Log | As a log property:
| |||||
Property | As a standalone property:
| |||||
PayloadFactory | As the payload arguments:
IMPORTANT: You MUST omit the | |||||
Switch | As the switch source:
| |||||
Filter | As the filter source:
|
Dynamic value support for JSONPath expressions
From EI 6.6.0 WUM timestamp 1596743391251 onwards, we are supporting dynamic JSONPath expressions.
Sample usage
json-eval($.[?(@.name=='{$ctx:customerName}')]) enclosing quotes needed when used with == operation
json-eval($.book.{$ctx:prep1}) no quotes needed when used as a part of the key
JSON path syntax
Suppose we have the following payload:
...
For more information on logging, see Troubleshooting, debugging, and logging below.
Constructing and transforming JSON payloads
...
Parameter | Description | Default Value |
---|---|---|
| Preserves the namespace declarations in the JSON output in XML to JSON transformations. | false |
| Builds valid XML NCNames when building XML element names in XML to JSON transformations. | false |
| Allows primitive types in the JSON output in XML to JSON transformations. | true |
| The namespace prefix separation character for the JSON output in XML to JSON transformations. | The default separation character is - |
| Adds XML namespace declarations in the JSON output in XML to JSON transformations. | false |
| Disables auto primitive conversion in XML to JSON transformations. | null |
| Sets the JSON output to an array element in XML to JSON transformations. | true |
| Sets the JSON output to an xml multiple processing instruction in XML to JSON transformations. | true |
| Sets the XML output to an array element in XML to JSON transformations. | true |
| Sets the XML output to an xml multiple processing instruction in XML to JSON transformations. | false |
synapse.commons.enableXmlNilReadWrite | Handles how empty XML elements with the 'nil' attribute are converted to JSON. | false |
| Handles how empty XML elements are converted to JSON. | true |
...
Validating JSON messages
You can use the Validate mediator to validate JSON messages against a specified JSON schema as described in the rest of this section.
...
Tip |
---|
When adding this sample schema file to the Registry, specify the Media Type as application/json. |
Code Block | ||
---|---|---|
| ||
{ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "getQuote": { "type": "object", "properties": { "request": { "type": "object", "properties": { "symbol": { "type": "string" } }, "required": [ "symbol" ] } }, "required": [ "request" ] } }, "required": [ "getQuote" ] } |
...