How to add variable into JSON string?
String yourVariable = "xyz";
def stringBody = '''
{
"first_name": "${yourVariable}",
"middle_name": "MOH",
"last_name": "API",
"date_of_birth": "12/12/2000"
}
'''
How to add variable into JSON string?
String yourVariable = "xyz";
def stringBody = '''
{
"first_name": "${yourVariable}",
"middle_name": "MOH",
"last_name": "API",
"date_of_birth": "12/12/2000"
}
'''
try…
def stringBody = """
...
"""
https://groovy-lang.org/syntax.html#_string_interpolation
Any Groovy expression can be interpolated in all string literals, apart from single and triple-single-quoted strings. Interpolation is the act of replacing a placeholder in the string with its value upon evaluation of the string.
Thanks @Russ_Thomas @kazurayam