This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, go to https://wso2.com/documentation/.

Map Extension

This extension provides the capability to send a map object inside Siddhi stream definitions and use it inside queries. The following are the functions of the map extension.

Create function

Syntax

<Object> map:create()

or

<Object> map:create(<Object> key1, <Object> value1,<Object> key2, <Object> value2,...<Object> keyN, <Object> valueN)

Extension TypeFunction
DescriptionReturns the created map object.
Examples
  • create() returns an empty map.
  • create(1 , ”one” ,  2 , ”two” , 3 , ”three”) returns a map with keys 1, 2, 3 and corresponding values "one", "two", "three".

 

Get function

Syntax<Object> map:get(<Map> map, <Object> key)
Extension TypeFunction
DescriptionReturns the value object from the map that is related to the given key.
Exampleget(company,1) returns the value that is related to the key 1 from the map named company.

 

Is Map function

Syntax<bool> map:isMap(<Object> object)
Extension TypeFunction
DescriptionReturns true if the object is a map or false otherwise.
ExampleisMap(students) returns true if the students object is a map. It returns false if the students object is not a map.

 

Put function

Syntax

<Object> map:put(<Object> map, <Object> key,<Object> value)

Extension TypeFunction
DescriptionReturns the updated map after adding the given key-value pair.
Exampleput(students , 1234 , ”sam”) returns the updated map named students after adding the object "sam" with key 1234.

 

Remove function

Syntax<Object> map:remove(<Object> map, <Object> key)
Extension TypeFunction
DescriptionReturns the updated map after removing the element with key.
Exampleremove(students , 1234) returns the updated map students after removing the element with the key 1234.


Create from JSON function

Syntax<Object> map:createFromJSON(<string> JSONstring)
Extension TypeFunction
DescriptionReturns the map created with the key values pairs given in the JSONstring.
ExamplecreateFromJSON(“{‘symbol' : 'IBM' , 'price' : 200, 'volume' : 100}”) returns a map with the keys "symbol""price", "volume", and with the values "IBM"200 and 100 respectively.

 

Create from XML function

Syntax<Object> map:createFromXML(<string> XMLstring)
Extension TypeFunction
DescriptionReturns the map created with the key values pairs given in the XMLstring.
ExamplecreateFromXML(“<company> <symbol> wso2 </symbol> <price> <100> </price> <volume> 200 </volume> </company>”) returns a map with the keys "symbol""price""volume", and with the values WSO2100 and 200 respectively.

 

To JSON function

Syntax<String> map:toJSON(<Object> map)
Extension TypeFunction
DescriptionConverts a map into a JSON object and returns the definition of that JSON object as a string.
ExampleIf "company" is a map with key value pairs ("symbol" : wso2)("volume" : 100), and ("price",200)toJSON(company) returns the string “{“symbol” : “wso2” , “volume” : 100 , “price” : 200}”.

 

To XML function

Syntax

<String> map:toXML(<Object> map)

or

<String> map:toXML(<Object> map, <String> rootElementName)

Extension TypeFunction
DescriptionReturns the map as an XML string.
Example

If "company" is a map with key value pairs (“symbol” : wso2)(“volume” : 100), and (“price” : 200),

toXML(company) returns the string “<symbol>wso2</symbol><volume><100></volume><price>200</price>".

toXML(company, "abcCompany") returns the string “<abcCompany><symbol>wso2</symbol><volume><100></volume><price>200</price></abcCompany>".