Skip to content

API Docs - v1.0.9

Json

getBool (Function)

This method will return the Boolean value of Json element corresponding to the given path. If there is no valid Boolean value at the given path, the method will return 'false'

Syntax

<BOOL> json:getBool(<STRING|OBJECT> json, <STRING> path)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
json The json input which is used get the value against the given path STRING
OBJECT
No No
path The path which is used to get the value from given json STRING No No

Examples EXAMPLE 1

define stream InputStream(json string);
from IpStream
select json:getBool(json,"$.name") as name
insert into OutputStream;

This will return the corresponding Boolean value to the given path

getDouble (Function)

This method will return the double value of Json element corresponding to the given path. If there is no valid Double value at the given path, the method will return 'null'

Syntax

<DOUBLE> json:getDouble(<STRING|OBJECT> json, <STRING> path)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
json The json input which is used get the value against the given path STRING
OBJECT
No No
path The path which is used to get the value from given json STRING No No

Examples EXAMPLE 1

define stream InputStream(json string);
from IpStream
select json:getDouble(json,"$.name") as name
insert into OutputStream;

This will return the corresponding double value to the given path

getFloat (Function)

This method will return the Float value of the Json element corresponding to the given path. If there is no valid Float value at the given path, the method will return 'null'

Syntax

<FLOAT> json:getFloat(<STRING|OBJECT> json, <STRING> path)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
json The json input which is used get the value against the given path STRING
OBJECT
No No
path The path which is used to get the value from given json STRING No No

Examples EXAMPLE 1

define stream InputStream(json string);
from IpStream
select json:getFloat(json,"$.name") as name
insert into OutputStream;

This will return the corresponding Float value based on the given path

getInt (Function)

This method will return the Integer value of Json element corresponding to the given path. If there is no valid Integer value at the given path, the method will return 'null'

Syntax

<INT> json:getInt(<STRING|OBJECT> json, <STRING> path)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
json The json input which is used get the value against the given path STRING
OBJECT
No No
path The path which is used to get the value from given json STRING No No

Examples EXAMPLE 1

define stream InputStream(json string);
from IpStream
select json:getInt(json,"$.name") as name
insert into OutputStream;

This will return the corresponding integer value based on the given path

getLong (Function)

This method will return the Long value of the Json element corresponding to the given path. Ifthere is no valid Long value at the given path, the method will return 'null'

Syntax

<LONG> json:getLong(<STRING|OBJECT> json, <STRING> path)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
json The json input which is used get the value against the given path STRING
OBJECT
No No
path The path which is used to get the value from given json STRING No No

Examples EXAMPLE 1

define stream InputStream(json string);
from IpStream
select json:getLong(json,"$.name") as name
insert into OutputStream;

This will return the corresponding Long value based on the given path

getObject (Function)

This method will return the object of Json element corresponding to the given path.

Syntax

<OBJECT> json:getObject(<STRING|OBJECT> json, <STRING> path)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
json The json input which is used get the value against the given path STRING
OBJECT
No No
path The path which is used to get the object from given json STRING No No

Examples EXAMPLE 1

define stream InputStream(json string);
from IpStream
select json:getObject(json,"$.name") as name
insert into OutputStream;

This will return the corresponding object to the given path

getString (Function)

This method will return the string value of Json element corresponding to the given path.

Syntax

<STRING> json:getString(<STRING|OBJECT> json, <STRING> path)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
json The json input which is used get the value against the given path STRING
OBJECT
No No
path The path which is used to get the value from given json STRING No No

Examples EXAMPLE 1

define stream InputStream(json string);
from IpStream
select json:getString(json,"$.name") as name
insert into OutputStream;

This will return the corresponding string value to the given path

isExists (Function)

This method allows to check whether there is any json element in the given path or not. If there is a valid json element in the given path, it will return true. If there is no valid json element, it will return false

Syntax

<BOOL> json:isExists(<STRING|OBJECT> json, <STRING> path)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
json The json input which is used to search the element with the given path STRING
OBJECT
No No
path The path which is used to search in the given input json STRING No No

Examples EXAMPLE 1

define stream InputStream(json string);
from IpStream
select json:isExists(json,"$.name") as name
insert into OutputStream;

This will return the true/false based existence of the given path

setElement (Function)

This method allows to insert elements to the given json based on the specified path. If there is no valid path given, it will return the original json. Otherwise it will return the new json

Syntax

<OBJECT> json:setElement(<STRING|OBJECT> json, <STRING> path, <STRING|BOOL|DOUBLE|FLOAT|INT|LONG|OBJECT> jsonelement, <STRING> key)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
json The json input which is used to insert the given value STRING
OBJECT
No No
path The path which is used to insert the given element to the input json STRING No No
jsonelement The json element which is inserted into the given input json STRING
BOOL
DOUBLE
FLOAT
INT
LONG
OBJECT
No No
key The key which is used to insert the given element to the input json STRING No No

Examples EXAMPLE 1

define stream InputStream(json string);
from IpStream
select json:setElement(json,"$.name") as name
insert into OutputStream;

This will return the corresponding json object based on the given path and json element

toObject (Function)

This method will return the json object related to given json string.

Syntax

<OBJECT> json:toObject(<STRING> json)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
json A valid json string which is used to generate the returned json object STRING No No

Examples EXAMPLE 1

define stream InputStream(json string);
from InputStream
select json:toJson(json) as jsonObject
insert into OutputStream;

This will return the json object related to given json string

toString (Function)

This method will return the json string related to given json object.

Syntax

<STRING> json:toString(<OBJECT> json)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
json A valid json object which is used to generate the json string OBJECT No No

Examples EXAMPLE 1

define stream InputStream(json string);
from IpStream
select json:toString(json) as jsonString
insert into OutputStream;

This will return a json string related to given json object

tokenize (Stream Processor)

This tokenizes the given json according the path provided

Syntax

json:tokenize(<STRING|OBJECT> json, <STRING> path, <BOOL> fail.on.missing.attribute)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
json The input json that should be tokenized using the given path. STRING
OBJECT
No No
path The path that is used to tokenize the given json STRING No No
fail.on.missing.attribute If this parameter is set to 'true' and a json is not provided in the given path, the event is dropped. If the parameter is set to 'false', the unavailability of a json in the specified path results in the event being created with a 'null' value for the json element. true BOOL Yes No
Extra Return Attributes
Name Description Possible Types
jsonElement The json element retrieved based on the given path and the json. STRING

Examples EXAMPLE 1

define stream InputStream (json string,path string);
@info(name = 'query1')
from InputStream#json:tokenize(json, path)
select jsonElement
insert into OutputStream;

This query performs a tokenization for the given json using the path specified. If the specified path provides a json array, it generates events for each element in that array by adding an additional attributes as the 'jsonElement' to the stream
e.g., jsonInput - {name:"John",enrolledSubjects:["Mathematics","Physics"]}, path - "$.enrolledSubjects"
If we use the configuration in this example, it generates two events with the attributes "Mathematics", "Physics".
If the specified path provides a single json element, it adds the specified json element as an additional attribute named 'jsonElement' into the stream
e.g., jsonInput - {name:"John",age:25}, path - "$.age"

tokenizeAsObject (Stream Processor)

This tokenizes the given json based on the path provided and returns the response as an object.

Syntax

json:tokenizeAsObject(<STRING|OBJECT> json, <STRING> path, <BOOL> fail.on.missing.attribute)

QUERY PARAMETERS

Name Description Default Value Possible Data Types Optional Dynamic
json The input json that should be tokenized using the given path. STRING
OBJECT
No No
path The path that is used to tokenize the given json STRING No No
fail.on.missing.attribute If this parameter is set to 'true' and a json is not provided in the given path, the event is dropped. If the parameter is set to 'false', the unavailability of a json in the specified path results in the event being created with a 'null' value for the json element. true BOOL Yes No
Extra Return Attributes
Name Description Possible Types
jsonElement The json element retrieved based on the given path and the json. OBJECT

Examples EXAMPLE 1

define stream InputStream (json string,path string);
@info(name = 'query1')
from InputStream#json:tokenizeAsObject(json, path)
select jsonElement
insert into OutputStream;

This query performs a tokenization for the given json using the path specified. If the specified path provides a json array, it generates events for each element in the specified json array by adding an additional attribute as the 'jsonElement' into the stream
e.g., jsonInput - {name:"John",enrolledSubjects:["Mathematics","Physics"]}, path - "$.enrolledSubjects"
If we use the configuration in the above example, it generates two events with the attributes "Mathematics", "Physics".
If the specified path provides a single json element, it adds the specified json element as an additional attribute named 'jsonElement' into the stream
e.g., jsonInput - {name:"John",age:25}, path - "$.age"