Forum Discussion
Hey!
Ok- I've been playing with a script I had before for replacing CDATA handler tags from an XML response - I thought I'd be able to use this but I'm struggling - my script is as follows at the moment (I'm using the jsonSlurper cos I'm struggling with the jsonUtil at moment - if I can get it to work with the jsonSlurper on v2.2.0 - I'll then get it working with the jsonUtil on v2.3.0)
Anyway - please see below:
import net.sf.json.groovy.* import groovy.json.JsonSlurper //grab the @odata.etag0 property def Jresponse = context.expand( '${Properties 1#@odata.etag0}' ) //parse the Jresponse variable which contains the @odata.etag0 property def json = new JsonSlurper().parseText Jresponse // Insert the escape chars ('\') into the Properties value response = Jresponse.replaceAll( "W/"", "W/\"" ) response = Jresponse.replaceAll( """", "\""" ) <<---struggling here
Now as stated in my first post - the value saved to the property is W/"123456" - I need to alter this property value to W/\"123456\"
I can insert the \ escape character after the / character - but I don't know the approach i should use to insert a \ before the last double quote (") - there's nothing unique for me to do a find a replace against to insert the \ escape char before the final double quote.
The original property value will always be in the format W/"nnnnnn" (where n = integer) - so I was wondering if there was some sort of substring function that could allow me to count and insert a \ char after the 9th char but before the 10th char?
I'm not a coder - but I'm really enjoying playing with groovy at the moment!
Anyway - I'd welcome any thought anyones has in regards to inserts the final \ escape character
Cheers,
richie
Related Content
- 9 months agoRichardPla