Jenkins Parse JSON Mantenha o pedido
Here is the solution: I realized that readJSON step is keeping the order so I try to take a look at its implementation.
readJSON uses net.sf.json.* library, in this library there is an option to parse string to jsonObject (with keeping the order of the keys!) by:
import net.sf.json.JSONSerializer
def map = JSONSerializer.toJSON(jsonstr)
println(map)
NOTES:
if you want use it during a pipeline I suggest you to use readJSON step itself, otherwise, you'll need to approve this function from Manage Jenkins -> script approval
In this method empty properties will be net.sf.json.JSONNull which holds a textual value "null" -> if (someEmptyKey != null) always returns true (also when null) to avoid that, use: if (!someEmptyKey instanceof JSONNull )
Sources: docs, jenkins-implementation
Unsightly Unicorn