API Docs - v1.0.11
Json
getBool (Function)
This method returns a 'boolean' value, either 'true' or 'false', based on the valuespecified against the JSON element present in the given path.In case there is no valid boolean value found in the given path, the method still returns '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 that holds the boolean value in the given path. | STRING OBJECT |
No | No | |
path | The path of the input JSON from which the 'getBool' function fetches theboolean value. | STRING | No | No |
Examples EXAMPLE 1
define stream InputStream(json string);
from InputStream
select json:getBool(json,"$.name") as name
insert into OutputStream;
This returns the boolean value of the JSON input in the given path. The results are directed to the 'OutputStream' stream.
getDouble (Function)
This method returns the double value of the JSON element present in the given path. If there is no valid double value in the given path, the method returns '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 that holds the value in the given path. | STRING OBJECT |
No | No | |
path | The path of the input JSON from which the 'getDouble' function fetches thedouble value. | STRING | No | No |
Examples EXAMPLE 1
define stream InputStream(json string);
from InputStream
select json:getDouble(json,"$.name") as name
insert into OutputStream;
This returns the double value of the given path. The results aredirected to the 'OutputStream' stream.
getFloat (Function)
This method returns the float value of the JSON element present in the given path.If there is no valid float value in the given path, the method returns '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 that holds the value in the given path. | STRING OBJECT |
No | No | |
path | The path of the input JSON from which the 'getFloat' function fetches thevalue. | STRING | No | No |
Examples EXAMPLE 1
define stream InputStream(json string);
from InputStream
select json:getFloat(json,"$.name") as name
insert into OutputStream;
This returns the float value of the JSON input in the given path. The results aredirected to the 'OutputStream' stream.
getInt (Function)
This method returns the integer value of the JSON element present in the given path. If there is no valid integer value in the given path, the method returns '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 that holds the value in the given path. | STRING OBJECT |
No | No | |
path | The path of the input JSON from which the 'getInt' function fetches theinteger value. | STRING | No | No |
Examples EXAMPLE 1
define stream InputStream(json string);
from InputStream
select json:getInt(json,"$.name") as name
insert into OutputStream;
This returns the integer value of the JSON input in the given path. The resultsare directed to the 'OutputStream' stream.
getLong (Function)
This returns the long value of the JSON element present in the given path. Ifthere is no valid long value in the given path, the method returns '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 that holds the value in the given path. | STRING OBJECT |
No | No | |
path | The path of the JSON element from which the 'getLong' functionfetches the long value. | STRING | No | No |
Examples EXAMPLE 1
define stream InputStream(json string);
from InputStream
select json:getLong(json,"$.name") as name
insert into OutputStream;
This returns the long value of the JSON input in the given path. The results aredirected to 'OutputStream' stream.
getObject (Function)
This returns the object of the JSON element present in 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 that holds the value in the given path. | STRING OBJECT |
No | No | |
path | The path of the input JSON from which the 'getObject' function fetches theobject. | STRING | No | No |
Examples EXAMPLE 1
define stream InputStream(json string);
from InputStream
select json:getObject(json,"$.name") as name
insert into OutputStream;
This returns the object of the JSON input in the given path. The results are directed to the 'OutputStream' stream.
getString (Function)
This returns the string value of the JSON element present in 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 that holds the value in the given path. | STRING OBJECT |
No | No | |
path | The path of the JSON input from which the 'getString' function fetches the string value. | STRING | No | No |
Examples EXAMPLE 1
define stream InputStream(json string);
from InputStream
select json:getString(json,"$.name") as name
insert into OutputStream;
This returns the string value of the JSON input in the given path. The results are directed to the 'OutputStream' stream.
isExists (Function)
This method checks whether there is a JSON element present in the given path or not.If there is a valid JSON element in the given path, it returns 'true'. If there is no valid JSON element, it returns '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 in a given path, on which the function performs the search forJSON elements. | STRING OBJECT |
No | No | |
path | The path that contains the input JSON on which the function performs the search. | STRING | No | No |
Examples EXAMPLE 1
define stream InputStream(json string);
from InputStream
select json:isExists(json,"$.name") as name
insert into OutputStream;
This returns either true or false based on the existence of a JSON element in a given path. The results are directed to the 'OutputStream' stream.
setElement (Function)
This method allows to insert elements into a given JSON present in a specific path. If there is no valid path given, it returns the original JSON. Otherwise, it returns 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 into which is this function inserts the new value. | STRING OBJECT |
No | No | |
path | The path on the JSON input which is used to insert the given element. | STRING | No | No | |
jsonelement | The JSON element which is inserted by the function into the input JSON. | STRING BOOL DOUBLE FLOAT INT LONG OBJECT |
No | No | |
key | The key which is used to insert the given element into the input JSON. | STRING | No | No |
Examples EXAMPLE 1
define stream InputStream(json string);
from InputStream
select json:setElement(json,"$.name") as name
insert into OutputStream;
This returns the JSON object present in the given path with the newly inserted JSONelement. The results are directed to the 'OutputStream' stream.
toObject (Function)
This method returns the JSON object related to a 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 from which the function generates the 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 returns the JSON object corresponding to the given JSON string.The results aredirected to the 'OutputStream' stream.
toString (Function)
This method returns the JSON string corresponding to a 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 from which the function generates a JSON string. | OBJECT | No | No |
Examples EXAMPLE 1
define stream InputStream(json string);
from InputStream
select json:toString(json) as jsonString
insert into OutputStream;
This returns the JSON string corresponding to a given JSON object. The results are directed to the 'OutputStream' stream.
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 |
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 is tokenized using the given path. | STRING OBJECT |
No | No | |
path | The path of the input JSON that the function tokenizes. | 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 |
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" and "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"