Closed millerbryan closed 4 years ago
Since I need to solve the same issue for the iotf toolkit I'll look at this.
FYI - I'm adding an operator to the streamsx.iotf toolkit that uses TupleToJson to create the JSON payload for a device command:
A use of it is here:
Basically the input schema is:
rstring deviceType, rstring deviceId, rstring cmdId, tuple<rstring eventId, int32 count> countInfo
So that the command payload is the nested tuple countInfo
resulting in the JSON payload being
{"eventId":"sensors","count":64}
and the full command received by a device using Quarks as:
{"command":"eventCount",
"tsms":1458256447624,
"format":"json",
"payload":{"eventId":"sensors","count":64}
}
Next step is to see if it's possible without forcing the use of a nested tuple, in this case supporting:
rstring deviceType, rstring deviceId, rstring cmdId, rstring eventId, int32 count
Note eventId is just a value in the command, as this app is basically aggregating event counts and sending them back to the device as device commands
Close this as it is an old issue and seems to be of kind "How to" and no replies are sent after last comment..
After reading through the docs a few times I am unable to determine how to tell my TupleToJSON operator what the output format should look like. I created a data type to represent the structure and it compiles OK but I get a runtime exception:
Exception in thread "Thread-11" java.lang.Exception: Attribute "myJsonString" must be one of the following types: [RSTRING, USTRING]
If I declare the output attribute to be of type rstring, the JSON is created but the hierarchy is flat and the root of the JSON structure is named myJsonString which I do not want.
I was able able figure out JSONToTuple but the docs are really fuzzy going the other way.