Skip to content

Instantly share code, notes, and snippets.

@abdrehma
Last active April 28, 2022 02:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdrehma/85e4b698f54944bf4eac9645e997bd8c to your computer and use it in GitHub Desktop.
Save abdrehma/85e4b698f54944bf4eac9645e997bd8c to your computer and use it in GitHub Desktop.
Jenkins readJSON is very dodgy with null values
def filterJSON(map){
map.each { key, value ->
if (value.toString() == "null"){
map[key] = null
} else if (value instanceof List){
map.eachWithIndex { item, index ->
if (item.toString() == "null"){
map[index] = null
}
}
} else if (value instanceof Map){
filterJSON(value)
}
}
}
def correctNullJSON = filterJSON(readJSON(file: "test.json"))
@grv87
Copy link

grv87 commented Apr 27, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment