(Groovy Version: 2.4.16 JVM: 11.0.8 Vendor: Debian OS: Linux)
My bash shell script outputs a JSON string that looks like this (without the "sout: "):
sout: {"vms":["Jenkins","UbuntuRunner"]}
Which I use as input to this Groovy code:
def sout = new StringBuilder()
def serr = new StringBuilder()
// translate JSON to List
def soutJson = new JsonSlurper().parseText(sout.toString())
log.append("sout: " + sout + "\n")
log.append("serr: " + serr + "\n")
log.append("soutJson: " + soutJson + "\n")
def List myList = soutJson.vms
log.append("myList: " + myList + "\n")
log.append("myList[0]: " + myList[0] + "\n")
log.append("myList[1]: " + myList[1] + "\n")
log.append("myList.size(): " + myList.size() + "\n")
I expect the output to include quotation marks, like this:
soutJson: ["vms":["Jenkins", "UbuntuRunner"]]
myList: ["Jenkins", "UbuntuRunner"]
myList[0]: "Jenkins"
myList[1]: "UbuntuRunner"
myList.size(): 2
But what is actually output is missing the quotes:
soutJson: [vms:[Jenkins, UbuntuRunner]]
myList: [Jenkins, UbuntuRunner]
myList[0]: Jenkins
myList[1]: UbuntuRunner
myList.size(): 2
Every example I find of printing a List or elements of the List include quotes. I don't care if these are single or double quotes but the code that later takes myList as input won't work if there are no quotes. And it can't be a string, it must be a List.
How do I retain the quotation marks?