Skip to content

API Docs - v1.0.8

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 will tokenize 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 which should be tokenized using the given path. STRING
OBJECT
No No
path The path which is used to tokenize the given json STRING No No
fail.on.missing.attribute This can either have value true or false. By default it will be true. If the specified path does not provide any json, it will return null. In this scenario users can drop or keep the event with 'null' value using this attribute. If this parameter is 'true', it will generate events with the 'null' value 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 tokenization for the given json using the path specified. If the specified path provides json array, it will generate events for each elements in specified json array by adding additional attribute as the 'jsonElement' into the stream
Eg:- jsonInput - {name:"John",enrolledSubjects:["Mathematics","Physics"]}, path - "$.enrolledSubjects"
It we use configuration like above example, it will generate two events with the attributes "Mathematics", "Physics".
If the specified path provides a single json element, it will add the specified json element as a additional attribute named 'jsonElement' into the stream
Eg:- jsonInput - {name:"John",age:25}, path - "$.age"

tokenizeAsObject (Stream Processor)

This will tokenize the given json according the path provided and return the response as 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 which should be tokenized using the given path. STRING
OBJECT
No No
path The path which is used to tokenize the given json STRING No No
fail.on.missing.attribute This can either have value true or false. By default it will be true. If the specified path does not provide any json, it will return null. In this scenario users can drop or keep the event with 'null' value using this attribute. If this parameter is 'true', it will generate events with the 'null' value 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 tokenization for the given json using the path specified. If the specified path provides json array, it will generate events for each elements in specified json array by adding additional attribute as the 'jsonElement' into the stream
Eg:- jsonInput - {name:"John",enrolledSubjects:["Mathematics","Physics"]}, path - "$.enrolledSubjects"
It we use configuration like above example, it will generate two events with the attributes "Mathematics", "Physics".
If the specified path provides a single json element, it will add the specified json element as a additional attribute named 'jsonElement' into the stream
Eg:- jsonInput - {name:"John",age:25}, path - "$.age"