Insert or replace a character in a string at a certain position

23 views
Skip to first unread message

Panneer

unread,
Jan 28, 2019, 7:47:10 PM1/28/19
to Jenkins Users
Hi All,

I want to insert  a character in a string at a certain position in Groovy pipeline. e.g is here below

sam1 = {"ttd1": [{:php2val2"}:{"Version" : "02.02.42"}

i want to convert the above data into below format for curl comman.

sam2 = {\"ttd1\": [{\"php2val2\"}:{\"Version"\ : \"02.02.42\"}

Please guide me on this.. I tried with replaceAll but not working.

Regards
Panneer

Rick

unread,
Jan 29, 2019, 2:13:37 AM1/29/19
to Mark Waite
Are you going to use this as a json string? You might consider the below example:

node {
    def abc = '''
    {"ttd1": [{:php2val2"}:{"Version" : "02.02.42"}
    '''
    
    echo abc
}

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/3558f89a-c446-4a3a-a45c-583f6012feb2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Panneer

unread,
Jan 29, 2019, 8:06:17 AM1/29/19
to Jenkins Users

Panneer

unread,
Jan 29, 2019, 8:08:37 AM1/29/19
to Jenkins Users
Hi,

correct. I am using JSON format only.. But jenkin not accepting your suggested format .
Already i tried. 

Thanks
Panneer

Jan Monterrubio

unread,
Jan 29, 2019, 10:05:47 AM1/29/19
to jenkins...@googlegroups.com
Groovy multi-line string uses 3 "

so

def jsony =  """
{
 "myJson": "isjson"
}
"""

Panneer

unread,
Jan 30, 2019, 11:32:03 PM1/30/19
to Jenkins Users
Thanks Jan.

Multi-line string helped me.

Regards
Panneer
Reply all
Reply to author
Forward
0 new messages