0

I am new to ReadyAPI and need your help in resolving below query. I have below JSON response and I need to get all the values that start with letter E.

[
   "E5008",
   "E5008",
   "E5008",
   "E5008",
   "V201-24",
   "4121",
   "4121",
   "4121",
   "V201-24",
   "4121",
   "4121",
}

I tried below one but no luck

import groovy.json.JsonSlurper

def jsonresponse=messageExchange.response.responseContent
def parsejson=new JsonSlurper().parseText(jsonresponse)

log.info parsejson[0]

def reqstr=parsejson.startswith("E")
log.info.reqstr
Vy Do
  • 46,709
  • 59
  • 215
  • 313
Shashi
  • 1

1 Answers1

0
...
def reqstr=parsejson.findAll{ it.startsWith("E") }
log.info( reqstr as String )
daggett
  • 26,404
  • 3
  • 40
  • 56
  • Thanks for your reply. I am getting an error when I included the above code Error in assertion script of the test step: No signature of method: java.lang.String.startswith() is applicable for argument types: (java.lang.String) values: [E] Possible solutions: startsWith(java.lang.String), startsWith(java.lang.String, int), startsWithAny([Ljava.lang.CharSequence;) – Shashi Jan 28 '22 at 04:05
  • That should be `startsWith` with a capital `W`. Seems you found a typo in daggett's code. Answer modified with the correct case. Daggett, hope this somewhat out of bounds typo fix was ok. – Matias Bjarland Jan 28 '22 at 05:25
  • @MatiasBjarland, thank you. that was just a copy-paste from original question ) – daggett Jan 28 '22 at 14:16
  • @MatiasBjarland - Tried with Capital W and getting below error Error in assertion script of the test step: No such property: info for class: org.apache.logging.log4j.core.Logger – Shashi Jan 28 '22 at 15:25
  • i've updated the answer. – daggett Jan 28 '22 at 15:38
  • Thank yo so much daggett and Matias. This one worked:) – Shashi Jan 31 '22 at 14:06
  • @Shashi: If this answer solved your problem, please remember to mark it as the accepted answer by clicking on the gray checkmark to the left of the answer. That will communicate to other members of the community that your question has been resolved to your satisfaction. – Jeremy Caney Feb 03 '22 at 00:47