Just starting out with Groovy and attempting to mock a service in SoapUI.
The task at hand involves loading a text file containing JSON data, and then matching that data to a specific node.
Here is what I have attempted so far:
def inputFile = new File("D:\\Users\\json.txt")
def InputJSON = new JsonSlurper().parseText(inputFile.text)
InputJSON.each{
def ID1 = it
it.items.each {
if(it.Number == itemNumber)
{
log.info it
requestContext.Id = ID1
}
}
}
While this works well, there is one problem – the format gets lost when ID1 loads into requestContext.Id from the file.
What I am aiming for is:
{
"items" {
"number" : 1475175072691
}
}
However, what I end up getting is:
{
metadata = {
timestamp = 1475175072691
}
}
I'm puzzled as to why the double quotes " and colon : are stripped from my JSON. Any suggestions on how to resolve this?