I am stuck in a scenario where i have created customized java code which returns a string. Next, I am passing it in another \path with JSON request below:

Given url 'url'
def browserCall = Java.type('package.browserCall')
 * def parameter = browserCall.method(data)// returns a string 
 Given path 'path'
* request 
 "data6":"{\"data7\":\"string\",\"data8\": \"+parameter+\"}",
 When method post
 Then status 200

When i hit it I get invalid JSON data object. I tried passing parameter as '#(parameter)' under data6 but did not get luck. tried to convert parameter to json and then passed it through data 6 but still did not get luck. I am not getting any lead. Please help.

  • I haven't used Karate, but the readme.md states "It is worth pointing out that JSON is a 'first class citizen' of the syntax such that you can express payload and expected data without having to use double-quotes and without having to enclose JSON field names in quotes. There is no need to 'escape' characters like you would have had to in Java or other programming languages."
    – ernie
    Commented Dec 7, 2017 at 18:59

1 Answer 1


Please read the “type conversion” section of the doc carefully: https://github.com/intuit/karate#type-conversion

Not the answer you're looking for? Browse other questions tagged or ask your own question.