API Docs - v5.2.2
Tested Siddhi Core version: 5.1.21
It could also support other Siddhi Core minor versions.
Sinkmapper
json (Sink Mapper)
This extension is an Event to JSON output mapper.
Transports that publish messages can utilize this extension to convert Siddhi events to JSON messages.
You can either send a pre-defined JSON format or a custom JSON message.
@sink(..., @map(type="json", validate.json="<BOOL>", enclosing.element="<STRING>", event.grouping.enabled="<BOOL>", enable.null.attribute.value="<BOOL>")
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
validate.json | If this property is set to |
false | BOOL | Yes | No |
enclosing.element | This specifies the enclosing element to be used if multiple events are sent in the same JSON message. |
$ | STRING | Yes | No |
event.grouping.enabled | This parameter is used to preserve event chunks when the value is set to 'true' or the value can be set to 'false' to separate events |
true | BOOL | Yes | No |
enable.null.attribute.value | If this parameter is true, output parameter values will contain null values if not they will be undefined |
false | BOOL | Yes | No |
Examples EXAMPLE 1
@sink(type='inMemory', topic='stock', @map(type='json'))
define stream FooStream (symbol string, price float, volume long);
Above configuration does a default JSON input mapping that generates the output given below.
{
"event":{
"symbol":WSO2,
"price":55.6,
"volume":100
}
}
EXAMPLE 2
@sink(type='inMemory', topic='{{symbol}}', @map(type='json', enclosing.element='$.portfolio', validate.json='true', @payload( """{"StockData":{"Symbol":"{{symbol}}","Price":{{price}}}}""")))
define stream BarStream (symbol string, price float, volume long);
The above configuration performs a custom JSON mapping that generates the following JSON message as the output.
{"portfolio":{
"StockData":{
"Symbol":WSO2,
"Price":55.6
}
}
}
Sourcemapper
json (Source Mapper)
This extension is a JSON-to-Event input mapper. Transports that accept JSON messages can utilize this extension to convert an incoming JSON message into a Siddhi event. Users can either send a pre-defined JSON format, where event conversion happens without any configurations, or use the JSON path to map from a custom JSON message.
In default mapping, the JSON string of the event can be enclosed by the element "event", though optional.
@source(..., @map(type="json", enclosing.element="<STRING>", fail.on.missing.attribute="<BOOL>", event.grouping.enabled="<BOOL>")
QUERY PARAMETERS
Name | Description | Default Value | Possible Data Types | Optional | Dynamic |
---|---|---|---|---|---|
enclosing.element | This is used to specify the enclosing element when sending multiple events in the same JSON message. |
$ | STRING | Yes | No |
fail.on.missing.attribute |
|
true | BOOL | Yes | No |
event.grouping.enabled | This parameter is used to preserve event chunks when the value is set to 'true' or the value can be set to 'false' to separate events |
true | BOOL | Yes | No |
Examples EXAMPLE 1
@source(type='inMemory', topic='stock', @map(type='json'))
define stream FooStream (symbol string, price float, volume long);
This configuration performs a default JSON input mapping.
For a single event, the input is required to be in one of the following formats:
{
"event":{
"symbol":"WSO2",
"price":55.6,
"volume":100
}
}
or
{
"symbol":"WSO2",
"price":55.6,
"volume":100
}
EXAMPLE 2
@source(type='inMemory', topic='stock', @map(type='json'))
define stream FooStream (symbol string, price float, volume long);
This configuration performs a default JSON input mapping.
For multiple events, the input is required to be in one of the following formats:
[
{"event":{"symbol":"WSO2","price":55.6,"volume":100}},
{"event":{"symbol":"WSO2","price":56.6,"volume":99}},
{"event":{"symbol":"WSO2","price":57.6,"volume":80}}
]
or
[
{"symbol":"WSO2","price":55.6,"volume":100},
{"symbol":"WSO2","price":56.6,"volume":99},
{"symbol":"WSO2","price":57.6,"volume":80}
]
EXAMPLE 3
@source(type='inMemory', topic='stock', @map(type='json', enclosing.element="$.portfolio", @attributes(symbol = "company.symbol", price = "price", volume = "volume")))
This configuration performs a custom JSON mapping.
For a single event, the expected input is similar to the one shown below:
{
"portfolio":{
"stock":{ "volume":100,
"company":{
"symbol":"WSO2"
},
"price":55.6
}
}
}
EXAMPLE 4
@source(type='inMemory', topic='stock', @map(type='json', enclosing.element="$.portfolio", @attributes(symbol = "stock.company.symbol", price = "stock.price", volume = "stock.volume")))
define stream FooStream (symbol string, price float, volume long);
The configuration performs a custom JSON mapping.
For multiple events, expected input looks as follows.
.{"portfolio":
[ {"stock":{"volume":100,"company":{"symbol":"wso2"},"price":56.6}}, {"stock":{"volume":200,"company":{"symbol":"wso2"},"price":57.6}} ]
}