Solved: Thanks to below answer from S.Richmond. I needed to unset all stored maps of the groovy.json.internal.LazyMap
type whi
According to best practices posted on Jenkins blog (Pipeline scalability best practice), it is strongly recommended to use command-line tools or scripts for this kind of work :
Gotcha: especially avoid Pipeline XML or JSON parsing using Groovy’s XmlSlurper and JsonSlurper! Strongly prefer command-line tools or scripts.
i. The Groovy implementations are complex and as a result more brittle in Pipeline use.
ii. XmlSlurper and JsonSlurper can carry a high memory and CPU cost in pipelines
iii. xmllint and xmlstartlet are command-line tools offering XML extraction via xpath
iv. jq offers the same functionality for JSON
v. These extraction tools may be coupled to curl or wget for fetching information from an HTTP API
Thus, it explains why most solutions proposed on this page are blocked by default by Jenkins security script plugin's sandbox.
The language philosophy of Groovy is closer to Bash than Python or Java. Also, it means it's not natural to do complex and heavy work in native Groovy.
Given that, I personally decided to use the following :
sh('jq file.json')
See jq Manual and Select objects with jq stackoverflow post for more help.
This is a bit counter intuitive because Groovy provides many generic methods that are not in the default whitelist.
If you decide to use Groovy language anyway for most of your work, with sandbox enabled and clean (which is not easy because not natural), I recommend you to check the whitelists for your security script plugin's version to know what are your possibilities : Script security plugin whitelists