Service Virtualization

 View Only
  • 1.  How to pass values into JSON request from excel

    Posted Dec 02, 2016 10:57 AM

    I am trying to run a test on a RESTful service, that communicates using JSON objects. When I run test with a JSON and I get response. I am trying to parameterize some values in JSON using excel. I replaced all the values in JSON with column name as {{ColumnName}}. However, when I run test with this, I get a response as "Bad Request: Invalid request payload JSON format".


    Is it not possible to parameterize JSON request or am I doing anything wrong..? 

  • 2.  Re: How to pass values into JSON request from excel

    Posted Dec 03, 2016 01:26 PM

    you can simply create a dynamic request by creating it in txt file then read that file and pass that step property to REST step it will automatically take all the parametric value and create a request for you and pass in the request body area.

  • 3.  Re: How to pass values into JSON request from excel
    Best Answer

    Posted Dec 06, 2016 10:52 AM

    Substitution should be possible. 

    Try breaking down your flow into some intermediate steps so you can debug some things.

    1) Place the JSON payload containing the {{}} substitutions into a DevTest property.  In this example, I will name this property "yourJSON".


    2) Set the properties you want replaced in the JSON payload.  Ensure that the properties contain the appropriate Upper & lower case characters in the property names.


    3) Add a JSR-223 step after you perform steps 1 & 2.  In this step, add a script to tell DevTest to parse the JSON payload, perform substitutions, and store the JSON in a new property called "someName":

    testExec.setStateValue( "someName", testExec.parseInState( testExec.getStateValue( "yourJSON") ) ); 


    Now, execute the above steps in ITR mode.  

    1) After executing the first step, ensure your property named "yourJSON" contains the JSON string with the {{}} coding.

    2) After executing the second step, ensure your substitution properties contain the values to be substituted.

    3) After the JSR step executes, look at the properties, and launch extended view on the property called "someName".


    What do you see in the JSON for the property "someName"?  

    Are the values substituted correctly?  

    If not, check the spelling of your property names.  

    If values substituted, check the format of the JSON to ensure that it is a) syntactically correct, and b) contains the format expected by the system you are sending it to.

  • 4.  Re: How to pass values into JSON request from excel

    Posted Dec 06, 2016 11:30 AM

    Hi Joel,


    You are awesome. When I was reading thru your response, I was thinking that its a long process to achieve. But, it was quick n easy. Thanks a bunch.