cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy If loop example

SOLVED
Highlighted
Occasional Contributor

Groovy If loop example

I am new to groovy scripting, am trying to loop through the rest response in below format

"addressData" : [
            {
               "type" : "MAILING",
                 "address" : {
                  "addressLines" : [
                     "",
                     "315 ST W"
                  ],
                  "city" : "",
                  "province" : "",
                  }
            },
            {
               "type" : "RESIDENTIAL",
               "verified" : false,
               "address" : {
                  "addressLines" : [
                     "",
                     ""
                  ],
                  "city" : "",
                  "province" : "",               
               }

 

I want to loop through and find the residential address and make sure has right value in every rest tag of that particular array, went through bideos but in time crunch.. hence wanna quick answer

 

ALSO, any appropriate course or tutorial on Groovy for READY API will really help

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super Contributor

Re: Groovy If loop example

Provided JSON is not correct. Here is the basic example how you can traverse through JSON:-

import groovy.json.JsonSlurper
def json = '''{"books":{"science":"biology", "commerce": "accountancy"}}'''

jSlurper = new JsonSlurper().parseText(json)
log.info (jSlurper.books.commerce);

This way if you have arrays of JSON, in that case you should use Using Gson . 

View solution in original post

3 REPLIES 3
Highlighted
Community Manager

Re: Groovy If loop example

Hi SubhaD,

 

Please refer to the Groovy Script article describing basic features.

Is this what you are looking for?

---------
Tanya Gorbunova
SmartBear Community Manager

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
Highlighted
Super Contributor

Re: Groovy If loop example

Provided JSON is not correct. Here is the basic example how you can traverse through JSON:-

import groovy.json.JsonSlurper
def json = '''{"books":{"science":"biology", "commerce": "accountancy"}}'''

jSlurper = new JsonSlurper().parseText(json)
log.info (jSlurper.books.commerce);

This way if you have arrays of JSON, in that case you should use Using Gson . 

View solution in original post

Highlighted
Community Manager

Re: Groovy If loop example

Hi @subhaD,

 

Did the suggestions given here answer your question?

---------
Tanya Gorbunova
SmartBear Community Manager

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today
New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Compete with community members in the TechCorner Challenge and get into the Leaderboard!

Rank Participant Points Earned
1 msiadak 9
2 nmrao 6
3 HimanshuTayal 3
Top Kudoed Authors