Skip to content

TupleToJSON Operator

Rohit Wagle edited this page Apr 25, 2014 · 13 revisions

The TupleTOJSON operator can be used to convert SPL tuples to JSON strings.

##Namespace

com.ibm.streamsx.json

##Parameters Following parameters are supported

jsonStringAttribute
This is an optional parameter that can be used to specify the name of the output stream attribute that should be populated with the JSON string. By default, the operator expects an attribute named "jsonString" to be present in the output stream. This attribute can be either of USTRING or RSTRING type.

rootAttribute This is an optional parameter that can be used to specify the name of an inner attribute of the input stream to be used as the root of the SPL type to be converted to JSON. The specified attribute can only be of TUPLE type. By default, the base of the input stream tuple is used to convert to JSON

##Examples

###Example 1 In this example, the JsonS stream attribute jsonString will have the value "{\"name\" : \"Jane\", \"age\": 25, \"relatives\" : [\"John\", \"Sam\" }"

    stream<JsonType> InputS = Beacon() {
      param
        iterations : 1u;
      output InputS : name = "Jane", age = 25, relatives = ["John", "Sam"];
    }
    
    stream<rstring jsonString> JsonS = TupleToJSON(InputS) {}
Clone this wiki locally