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.

closed as off-topic by c32hedge, IAmMilinPatel, alecxe Dec 10 '17 at 22:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers." – c32hedge, IAmMilinPatel, alecxe
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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 Dec 7 '17 at 18:59

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.