How to add variable into JSON string?

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"
}
'''

image

try…

def stringBody = """
         ...
"""
1 Like

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.

1 Like

Thanks @Russ_Thomas @kazurayam