Manu
Manu

Reputation: 75

WSO2 SP: Construct JSON object from stream

I'm trying to generate a JSON object, from a stream of JSON data, using below clode:

@sink(type='log')
define stream TempStream(designation object);

from TestStream
select json:setElement("{}", "$", json:getString(json,"$.DESIGNATION"), "designation") as designation
insert into TempStream;

But the output data having null value. Is there any issue with the code, please?

TempStream : Event{timestamp=1554192487415, data=[null], isExpired=false} 

The input stream having data passed as below:

TestStream : Event{timestamp=1554192487415, data=[{"STATUS":"AA","CREATED_DATE":"2010-11-23 10:24:36","DESIGNATION":"Manager"}], isExpired=false}

Upvotes: 0

Views: 213

Answers (1)

Anusha Jayasundara
Anusha Jayasundara

Reputation: 168

I have checked this on a SP 4.3.0 pack and I was able to get the following result

 SiddhiApp : TempStream : Event{timestamp=1554733451717, data=[{designation=Manager}], isExpired=false}

The Query that I used as follows with the event that I send to the "TestStream",

@sink(type='log',"TEMPSTREAM")
define stream TempStream(designation object);

@sink(type='log')
define stream TestStream(json string);

from TestStream
select json:setElement("{}", "$", json:getString(json,"$.DESIGNATION"), "designation") as designation
insert into TempStream;
SiddhiApp : TestStream : Event{timestamp=1554733451717, data=[{ "STATUS": "AA", "CREATED_DATE": "2010-11-23 10:24:36", "DESIGNATION": "Manager" } ], isExpired=false}

I beleave this is the result that you are expecting.

Upvotes: 1

Related Questions