Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse NAs when reading in json files #524

Merged
merged 4 commits into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/Utils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Utils {
*/
static def readMeta(file) {
def meta = new JsonSlurper().parse(file)
meta = meta.each{ key, value -> meta[key] = this.parseNA(value) }

return(meta)
}

Expand All @@ -38,8 +40,9 @@ class Utils {
*/
static def getMetaVal(file, key){
def obj = new JsonSlurper().parse(file)
def value = this.parseNA(obj[key])

return(obj[key])
return(value)
}


Expand All @@ -52,9 +55,13 @@ class Utils {
*/
static def parseNA(str) {
if (str){
str.toLowerCase() in ['na','n/a','nan']? '' : str
} else {
if (str instanceof String) { // has to be a string to have NA vals replaced
str.toLowerCase() in ['na','n/a','nan']? '' : str
} else { // not a string, so just return the unmodified value
str
}
} else { // all falsey values get turned into empty strings
''
}
}
}
}