Forum Discussion

Markus_F's avatar
Markus_F
Occasional Contributor
6 years ago
Solved

Extract certain strings from JSON data strucure

Hello community,   I have the following JSON formatted data: {    "interfaces" : {       "interface" : [          {             "interface-name" : "eth0"          },          {          ...
  • TNeuschwanger's avatar
    TNeuschwanger
    6 years ago

    Hello Markus,

    Given that you have a list of values that can vary between 0 and infinity, you can set properties from it easily enough, but now you have to give the property a name for each of those values. For each value a unique name must be created unless you don't care about how many values are in a list. The following builds on prior examples in this thread:

     

    filteredInterfaceNameList = [];
    interfaceNameList.each { name ->
       if (name.contains('cons')) {
          filteredInterfaceNameList.add (name)
       };
    };


    filteredInterfaceNameList.eachWithIndex { interfaceName, idx ->
       propName = "somePropertyNameValue" + idx.toString();
       propValue = interfaceName;
       testRunner.testCase.testSteps["Properties"].setPropertyValue( propName, propValue);
    };

    .

    .

    .
    You have never stated how you would use this dynamically, so I can only imagine... The above code allows you to dynamically write properties from 0 to infinity (or however many Smartbear will allow). :)