Service Virtualization

Expand all | Collapse all

Adding Properties to JSON

Jump to Best Answer
  • 1.  Adding Properties to JSON

    Posted 06-07-2018 01:44 AM

    I have a response from a Rest Step in JSON format, i want to add few more properties to this JSON(root) response and use it as a payload for another Rest Step.

     

    Can anyone please help with the steps to implement this in LISA?

     

    Thanks



  • 2.  Re: Adding Properties to JSON
    Best Answer

    Posted 06-07-2018 09:00 AM

    You are most likely going to need to develop a custom script to insert the additional JSON data. There is no out-of-box capability for dynamically adding in additional content. You might substring and splice the content into the JSON payload or you could create JSON objects and manipulate the content according to methods exposed by those objects.



  • 3.  Re: Adding Properties to JSON

    Posted 08-27-2018 04:48 PM

    J_NeSmith What if I've to add an integer Lisa property in a JSON?

     

    Eg:

    JSON

    {

    "number":{{lisa_property}}

    }

     

    This is giving an error. How to overcome this?



  • 4.  Re: Adding Properties to JSON

    Posted 08-28-2018 08:37 AM

    What sort of error are you seeing?



  • 5.  Re: Adding Properties to JSON

    Posted 08-28-2018 12:52 PM

     

    The JSON is invalid. But somehow if I ignore this error, it just works fine. Quite strange. But it's fine. Thanks for your help though.



  • 6.  Re: Adding Properties to JSON

    Posted 08-28-2018 01:55 PM

    That's strange. 

    As a test and after the {{ISN}} value is assigned in the test

    - Add a Parse Text as Response step and copy/paste the above JSON

    - Save it in some property - let's call the property myJson.

    - Add a Scripted Assertion in the Parse Text step having the following.

    Set the step to Fail if the return is False - in case I made a typo below.

    testExec.setStateValue("myJson", testExec.parseInState( testExec.getStateValue("myJson") ) );

    _logger.info("isn value is: {}, testExec.getStateValue("ISN") );

    _logger.info("Parsed Json is:\r\n{}", testExec.getStateValue("myJson") );

    return true;

    - Execute the test in ITR mode and after the step executes, check the Events Tab for the two logger displays.

    Do the events show the correct value of isn?

    And, did TestExec parse the value of "ISN" in the myJson property?

    DevTest shouldn't care if the JSON is valid or not in the above as no validation is applied. 



  • 7.  Re: Adding Properties to JSON

    Posted 08-28-2018 07:41 PM

    J_NeSmith Yeah. It's a bit strange. I'm getting the correct value for the property. Only the JSON, with the {{ISN}} is invalid. During the run, when {{ISN}} is replaced by actual value, it's all good.