Striim 3.10.1 documentation

JSONNode functions

Use the following functions in CQs with an input and/or output stream of type JSONNodeEvent, or to create or manipulate any other JSONNode objects.

When the JSONNode objects are supplied by the CQ's input stream, JsonNode node is the DATA element of JSONNodeEvent. If there is more than one JSONNodeEvent input stream, choose one by using an alias for the stream, for example, s.data.

function

description

notes

AVROTOJSON(Object datum, Boolean IgnoreNulls)

convert an Avro node to a JSON node

Object datum must be an Avro GenericRecord present in an AvroEvent output by a source using an AvroParser.

If Boolean IgnoreNulls is true, any Avro fields with null values will be omitted from the JSON, so, for example, {a: 100, b: null, c: 'test'} will return{a:100, c:'test'}.

clearUserData()

 

See Adding user-defined data to JSONNodeEvent streams.

JSONArrayAdd(JsonNode node, Object value)

add object value at the end of array node

Use .get() to select the array. For example, JSONArrayAdd(data.get("PhoneNumbers"),"987") will add 987 to the end of the PhoneNumbers array node.

JSONArrayInsert(JsonNode node, int index, Object value)

add object value as an element at position index in array node

Use .get to select the array. For example, JSONArrayInsert(data.get("PhoneNumbers"),0,"987") will insert 987 at the beginning of the PhoneNumbers array. Object value must be deserialized as per Jackson ObjectMapper.readTree.

JSONFrom(Object value)

create a JSONNode from object value

For example, JSONFrom('{ "name":"John", "age":30, "city":"New York"}'). Object value must be deserialized as per Jackson ObjectMapper.readTree.

JSONGetBoolean(JsonNode node, String field)

get a Boolean value from specified field of JSONNode node

If the field is a Boolean, returns true or false. For other types, returns false.

JSONGetDouble(JsonNode node, String field)

get a double value from specified field of JSONNode node

If the field is numeric (that is, isNumber() returns true), returns a 64-bit floating point (double) value. For other types, returns 0.0. For integer values, conversion is done using default Java type coercion. With BigInteger values, this may result in overflows.

JSONGetInteger(JsonNode node, String field)

get an integer value from specified field of JSONNode node

If the field is numeric (that is, isNumber() returns true), returns an integer value. For other types, returns 0. For floating-point numbers, the value is truncated using default Java type coercion.

JSONGetString(JsonNode node, String field)

get a string value from specified field of JSONNode node

Non-string values (that is, ones for which isTextual() returns false) are returned as null. Empty string values are returned as empty strings.

JSONNew()

create an empty JSONNode object

JSONRemove(JsonNode node, Collection< String >fieldNames)

remove specified fields from of JSONNode node

For example, SELECT JSONRemove(data, "ID").

JSONSet(JsonNode node, String field, Object value)

set the value specified field in specified JSONNode to object value

Overwrites any existing value. Object value must be deserialized as per Jackson ObjectMapper.readTree.

makeJSON(String jsonText)

create a JSONNode

 

putUserdata()

 

See Adding user-defined data to JSONNodeEvent streams.

removeUserData()

 

See Adding user-defined data to JSONNodeEvent streams.

TO_JSON_NODE(Object obj)

convert object to a JSON node

Object must be in ObjectMapper.readTree format.

USERDATA()

 

See Adding user-defined data to JSONNodeEvent streams.