Forum Discussion

subhaD's avatar
subhaD
Contributor
6 years ago

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" : {      ...
  • avidCoder's avatar
    6 years ago

    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 .