C++ Native Functions: com.ibm.streamsx.json

IBM Streams com.ibm.streamsx.json Toolkit > com.ibm.streamsx.json 1.5.1 > com.ibm.streamsx.json > C++ Native Functions

This page documents native functions that can be invoked from SPL, including the SPL interfaces that can be used to invoke each of the native functions.

Functions

<tuple T> public T extractFromJSON(rstring jsonString, mutable T value)

Extract values from JSON string accordingly to a given tuple. Blob, complex, xml, timestamp and decimal type attributes are not supported. Collections don't support nesting. Optional types are supported for primitive types and list and set of primitive types only. Optional bounded types are not supported.

Parameters
jsonString

The input JSON string.

value

A mutable tuple to save extracted values.

Returns

Reference to the input tuple.

public rstring getParseError(JsonParseStatus.status status)

Get parse error string.

Parameters
status

a status of the parser to translate to a string.

Returns

Error string.

<string S, any T> public rstring mapToJSON(map<S, T> m)

Convert a map to JSON object encoded as a serialized JSON string. Blob, complex and xml values are converted to nulls. Timestamp is converted to a date string representation.

Parameters
m

Map containing key-value pairs to be converted to JSON.

Returns

Serialized JSON object containing all name-value pairs in m.

<string S, any T> public rstring mapToJSON(map<S, T> m, rstring prefixToIgnore)

Convert a map to JSON object encoded as a serialized JSON string. Blob, complex and xml values are converted to nulls.

Parameters
m

Map containing key-value pairs to be converted to JSON.

prefixToIgnore

rstring prefix to ignore in attribute name .

Returns

Serialized JSON object containing all name-value pairs in m.

<enum E> public uint32 parseJSON(rstring jsonString, E jsonIndex)

Parse JSON string (used in conjunction with queryJSON function). Threading limitations: Call to parseJSON should not be placed in param section or state of the operator (internally a json object is shared via the thread local storage).

Parameters
jsonString

The input JSON string.

jsonIndex

Json index of enum type (e.g. enum{_1}).

Returns

Error code (0 - no error).

<enum E> public boolean parseJSON(rstring jsonString, mutable JsonParseStatus.status status, mutable uint32 offset, E jsonIndex)

Parse JSON string (used in conjunction with queryJSON function). Threading limitations: Call to parseJSON should not be placed in param section or state of the operator (internally a json object is shared via the thread local storage).

Parameters
jsonString

The input JSON string.

status

indicates a status of the parser (enum JsonParseStatus.status).

offset

returns the offset in JSON string where parse error occured (use when status returns error).

jsonIndex

Json index of enum type (e.g. enum{_1}).

Returns

Error code (0 - no error).

<floatingpoint T, enum E> public T queryJSON(rstring jsonPath, T defaultVal, E jsonIndex)

Query JSON object for floatingpoint value with a given path (parseJSON function should be run before).

Parameters
jsonPath

Path to a JSON attribute.

defaultVal

Default value to apply when an attribute not found.

jsonIndex

Json index of enum type (e.g. enum{_1}).

Returns

JSON value.

<integral T, enum E> public T queryJSON(rstring jsonPath, T defaultVal, E jsonIndex)

Query JSON object for integral value with a given path (parseJSON function should be run before).

Parameters
jsonPath

Path to a JSON attribute.

defaultVal

Default value to apply when an attribute not found.

jsonIndex

Json index of enum type (e.g. enum{_1}).

Returns

JSON value.

<string T, enum E> public T queryJSON(rstring jsonPath, T defaultVal, E jsonIndex)

Query JSON object for string value with a given path (parseJSON function should be run before).

Parameters
jsonPath

Path to a JSON attribute.

defaultVal

Default value to apply when an attribute not found.

jsonIndex

Json index of enum type (e.g. enum{_1}).

Returns

JSON value.

<floatingpoint T, enum E> public T queryJSON(rstring jsonPath, T defaultVal, mutable JsonStatus.status status, E jsonIndex)

Query JSON object for floatingpoint value with a given path (parseJSON function should be run before).

Parameters
jsonPath

Path to a JSON attribute.

defaultVal

Default value to apply when an attribute not found.

status

indicates a status of the query (enum JsonStatus.status).

jsonIndex

Json index of enum type (e.g. enum{_1}).

Returns

JSON value.

<integral T, enum E> public T queryJSON(rstring jsonPath, T defaultVal, mutable JsonStatus.status status, E jsonIndex)

Query JSON object for integral value with a given path (parseJSON function should be run before).

Parameters
jsonPath

Path to a JSON attribute.

defaultVal

Default value to apply when an attribute not found.

status

indicates a status of the query (enum JsonStatus.status).

jsonIndex

Json index of enum type (e.g. enum{_1}).

Returns

JSON value.

<string T, enum E> public T queryJSON(rstring jsonPath, T defaultVal, mutable JsonStatus.status status, E jsonIndex)

Query JSON object for string value with a given path (parseJSON function should be run before).

Parameters
jsonPath

Path to a JSON attribute.

defaultVal

Default value to apply when an attribute not found.

status

indicates a status of the query (enum JsonStatus.status).

jsonIndex

Json index of enum type (e.g. enum{_1}).

Returns

JSON value.

<enum E> public boolean queryJSON(rstring jsonPath, boolean defaultVal, E jsonIndex)

Query JSON object for boolean value with a given path (parseJSON function should be run before). Threading limitations: Call to queryJSON should not be placed in param section or state of the operator (internally a json object is shared via the thread local storage).

Parameters
jsonPath

Path to a JSON attribute.

defaultVal

Default value to apply when an attribute not found.

jsonIndex

Json index of enum type (e.g. enum{_1}).

Returns

JSON value.

<enum E> public boolean queryJSON(rstring jsonPath, boolean defaultVal, mutable JsonStatus.status status, E jsonIndex)

Query JSON object value with a given path (parseJSON function should be run before).

Parameters
jsonPath

Path to a JSON attribute.

defaultVal

Default value to apply when an attribute not found.

status

indicates a status of the query (enum JsonStatus.status).

jsonIndex

Json index of enum type (e.g. enum{_1}).

Returns

JSON value.

<floatingpoint T, enum E> public list<T> queryJSON(rstring jsonPath, list<T> defaultVal, E jsonIndex)

Query JSON object for list of floatingpoint values with a given path (parseJSON function should be run before).

Parameters
jsonPath

Path to a JSON attribute.

defaultVal

Default value to apply when an attribute not found.

jsonIndex

Json index of enum type (e.g. enum{_1}).

Returns

JSON value.

<integral T, enum E> public list<T> queryJSON(rstring jsonPath, list<T> defaultVal, E jsonIndex)

Query JSON object for list of integrals with a given path (parseJSON function should be run before).

Parameters
jsonPath

Path to a JSON attribute.

defaultVal

Default value to apply when an attribute not found.

jsonIndex

Json index of enum type (e.g. enum{_1}).

Returns

JSON value.

<string T, enum E> public list<T> queryJSON(rstring jsonPath, list<T> defaultVal, E jsonIndex)

Query JSON object for list of strings with a given path (parseJSON function should be run before).

Parameters
jsonPath

Path to a JSON attribute.

defaultVal

Default value to apply when an attribute not found.

jsonIndex

Json index of enum type (e.g. enum{_1}).

Returns

JSON value.

<floatingpoint T, enum E> public list<T> queryJSON(rstring jsonPath, list<T> defaultVal, mutable JsonStatus.status status, E jsonIndex)

Query JSON object for list of floatingpoint values with a given path (parseJSON function should be run before).

Parameters
jsonPath

Path to a JSON attribute.

defaultVal

Default value to apply when an attribute not found.

status

indicates a status of the query (enum JsonStatus.status).

jsonIndex

Json index of enum type (e.g. enum{_1}).

Returns

JSON value.

<integral T, enum E> public list<T> queryJSON(rstring jsonPath, list<T> defaultVal, mutable JsonStatus.status status, E jsonIndex)

Query JSON object for list of integrals with a given path (parseJSON function should be run before).

Parameters
jsonPath

Path to a JSON attribute.

defaultVal

Default value to apply when an attribute not found.

status

indicates a status of the query (enum JsonStatus.status).

jsonIndex

Json index of enum type (e.g. enum{_1}).

Returns

JSON value.

<string T, enum E> public list<T> queryJSON(rstring jsonPath, list<T> defaultVal, mutable JsonStatus.status status, E jsonIndex)

Query JSON object for list of strings with a given path (parseJSON function should be run before).

Parameters
jsonPath

Path to a JSON attribute.

defaultVal

Default value to apply when an attribute not found.

status

indicates a status of the query (enum JsonStatus.status).

jsonIndex

Json index of enum type (e.g. enum{_1}).

Returns

JSON value.

<enum E> public list<boolean> queryJSON(rstring jsonPath, list<boolean> defaultVal, E jsonIndex)

Query JSON object for list of booleans with a given path (parseJSON function should be run before).

Parameters
jsonPath

Path to a JSON attribute.

defaultVal

Default value to apply when an attribute not found.

jsonIndex

Json index of enum type (e.g. enum{_1}).

Returns

JSON value.

<enum E> public list<boolean> queryJSON(rstring jsonPath, list<boolean> defaultVal, mutable JsonStatus.status status, E jsonIndex)

Query JSON object for list of booleans with a given path (parseJSON function should be run before).

Parameters
jsonPath

Path to a JSON attribute.

defaultVal

Default value to apply when an attribute not found.

status

indicates a status of the query (enum JsonStatus.status).

jsonIndex

Json index of enum type (e.g. enum{_1}).

Returns

JSON value.

<string S, any T> public rstring toJSON(S key, T value)

Convert a value to JSON object with a single key encoded as a serialized JSON string. Blob, complex and xml values are converted to nulls. An input value of type optional being null will generate also null in JSON.

Parameters
key

Key for name-value pair to be converted to JSON.

value

Value for key.

Returns

Serialized JSON object containing single name-value pair.

<string S, any T> public rstring toJSON(S key, T value, rstring prefixToIgnore)

Convert a value to JSON object with a single key encoded as a serialized JSON string. Blob, complex and xml values are converted to nulls.

Parameters
key

Key for name-value pair to be converted to JSON.

value

Value for key.

prefixToIgnore

rstring prefix to ignore in attribute name .

Returns

Serialized JSON object containing single name-value pair.

<tuple T> public rstring tupleToJSON(T t)

Convert a tuple to JSON object encoded as a serialized JSON String. Blob, complex and xml values are converted to nulls. Timestamp is converted to a date string representation. Optional attributes having null value are converted to null in JSON.

Parameters
t

Tuple to be converted to JSON.

Returns

Tuple encoded as a serialized JSON object.

<tuple T> public rstring tupleToJSON(T t, rstring prefixToIgnore)

Convert a tuple to JSON object encoded as a serialized JSON String. Blob, complex and xml values are converted to nulls.

Parameters
t

Tuple to be converted to JSON.

prefixToIgnore

rstring prefix to ignore in attribute name .

Returns

Tuple encoded as a serialized JSON object.