Forum Discussion

rajs2020's avatar
rajs2020
Frequent Contributor
4 years ago
Solved

Groovy best practices - How to set the root node when extracting data from a response?

See this code:   def jobDate = context.expand( '${GetJobInfo#Response#$[\'jobData\'][0][\'jobDate\']}' )   I see this kind of code too many times in a codebase. For example, it will be repeat...
  • HimanshuTayal's avatar
    4 years ago

    rajs2020 : If it is an array, then instead of using context of expand you can use jsonSlurper to get the value from the array by iterating over each element. Refer below link for documentation

     

    json-slurper