How do I prevent a file path from being altered when being parsed by JsonSlurper in Groovy Script?
I have a Groovy Script step which parses though a number of JSON objects from a REST response and saves certain parameters to be used in a following REST request. One of these parameters is the file path of the associated JSON object. Its format is: "C:\\ProgramData\\Folder1\\Folder2\\..."
The problem is that when I parse the JSON response using a JsonSlurper the file path format is altered to "C:\ProgramData\Folder1\Folder2\..." removing one of the '\' characters. This format is not accepted in the request I need it for and I cannot seem to find any information on how to prevent this from happening. Can anyone help?
I was able to find a solution. I added the following line to my groovy script to reformat the file path before saving it in the test case parameters. Heres the line:
fullFilePath = fullFilePath.replaceAll("\\\\", "\\\\\\\\")
because a '\' is considered a special character I had to represent it differently in the replaceAll method. The string "\\\\" actually represents a single '\' character and so by doubling the number to 8 backslash characters I was able to properly replace the single '\' with the double backslash again.