Service Virtualization

 View Only
  • 1.  Dynamic JSON Response

    Posted Aug 10, 2020 12:53 PM
    Hi, I am creating a VS, Its REST API post method, it has to generate a JSON Response.
    I created VSM using RR pair, Now I need to send dynamic JSON response, the nodes in the JSON are dynamic.
    I created the JSON using JSR groovy script, and assigned to a property using testExec.setStateObject("JSONRSP", NEWJSONFROMSCRIPT).
    How can I pull the JSONRSP in the vsi response?
    I selected the Response type as JSON in the VSI response and in text mode editor will giving {{{JSONRSP}}} it throws invalid property.
    I am not able to generate dynamic JSON response. Is there a solution how to call the dynamic JSON?


  • 2.  RE: Dynamic JSON Response

    Broadcom Employee
    Posted Aug 10, 2020 02:10 PM
    Hello Srinivasan,

                    If you are setting the JSON response in a property JSONRSP, you an use testExec.setStateValue. In addition, to get the response in your VSI, use the property enclosed in two braces {{JSONRSP}}.Please try and let me know. 

    Regards,
    Surya



    ------------------------------
    Client Services Consultant
    Broadcom
    ------------------------------



  • 3.  RE: Dynamic JSON Response

    Posted Aug 12, 2020 07:24 AM
    For JSON text editor and Treeview is expecting the {} as default JSON format, As we use only {{JSONRSP}}, it converted into text response.
    So followed this, kept the outer node and defined the inner as a property 

    {"glossary":{{JSONRSP}}}

    it worked well, now my VS is giving the out that generated in the script.

    Thanks


  • 4.  RE: Dynamic JSON Response

    Posted Aug 11, 2020 12:03 AM
    Hi Srinivasan,

    You used an extra curly brace in your variable declaration within vsi. Use two curly braces for start and end i.e  {{variableName}} and try.

    Also, make sure your JSR script step is getting executed and not being skipped because of any assertions etc.

    Thanks

    ------------------------------
    Regards,
    Vaibhav Jain
    Capgemini
    ------------------------------



  • 5.  RE: Dynamic JSON Response
    Best Answer

    Posted Aug 12, 2020 07:25 AM
    For JSON text editor and Treeview is expecting the {} as default JSON format, As we use only {{JSONRSP}}, it converted into text response.
    So followed this, kept the outer node and defined the inner as a property 

    {"glossary":{{JSONRSP}}}

    it worked well, now my VS is giving the out that generated in the script.

    Thanks