Forum Discussion

abhinaykumar15's avatar
abhinaykumar15
Occasional Contributor
8 months ago
Solved

Unable to parse multiple json received in kafka Eventhub

Hi All,

I have a Eventhub to receive messages as and when they are published.I may receive multiple json messages.So i parse each of them using the Property-list-data field and try to assert certain fields in

all the received jsons.

But i am getting a error when i try to access a particular field in the received json.

I am trying something like this.

 
import groovy.json.*
import groovy.util.*
import groovy.json.JsonSlurper
 
 
//Parse JSON content in the request
def data = context.expand( '${Receive Message#data#$[*]}' )
def json=new JsonSlurper().parseText(data)
 
assert json.eventID=='1234546' || '1234545'-----This works fine
 
def i=1
while(i!=0)
{
 
def data2 = context.expand( '${Receive Message#data}' )
def json2=new JsonSlurper().parseText( data2)
log.info json2[i]
if (json6[i].eventID=='1234546')--------------This gives Error -Error is mentioned at the bottom of this post.
{
i=0;
log.info "Test Success"
}else{
i=i+1
}
 
}

 

Error :

groovy.lang.MissingPropertyException: No such property: eventID for class: java.lang.String
error at line: 20

 

Json that is received is as .I receive multiple such json in the same format.

{
   "eventID" : "1234546",
   "eventTimeStamp" : "2017-07-21T17:32:28Z",
   "eventType" : "EVENT_PUB",
   "Identifier1" : "",
   "Identifier2" : "",
   "shipinfo" : {
      "InfoNumber" : "123456",
      "originLoc" : "IND",
      "destLoc" : "IND",
     
   },
  
  
}

Please help .What am i missing here.

1 Reply

  • Guigz's avatar
    Guigz
    Occasional Contributor

    I changed the "Keys" manipulation part for "if else" that click directly the chosen item separately instead of trying to do it dynamically. This might not be viable for combobox with a lot of items, but I only had 4 and it seem to work in my case. 

    • Guigz's avatar
      Guigz
      Occasional Contributor

      When I manually try to reproduce the steps, the window stay open as I would expect.

      • Guigz's avatar
        Guigz
        Occasional Contributor

        I just saw that before clicking the button I select an item from a combobox dropdown using the Keys("[Up]") and Keys("[Enter]"). If I don't do that part the window don't disappear, but I still need to do that part