Forum Discussion

stephen_araghun's avatar
stephen_araghun
Occasional Contributor
11 years ago

Creating JSON from Testcomplete Objects

Hello Testcomplete Community!



I would like to know if it is possible to create JSON from testcomplete objects. So far this code fails when starting the For In loop:




function lookdeep(object){


      var collection= [], index= 0, next, item;


      for(item in object){


          if(object.hasOwnProperty(item)){


              next= object[item];


              if(typeof next== 'object' && next!= null){


                  collection[index++]= item +


                  ':{ '+ lookdeep(next).join(', ')+'}';


              }


              else collection[index++]= [item+':'+String(next)];


          }


      }


      return collection;


  }



The object supplied is from the objects spy on screen to a mapped object (in this case a gird.)



Thank you all in advance!



Stephen

2 Replies

  • Philip_Baird's avatar
    Philip_Baird
    Community Expert

    Hi Stephen, I think the problem you are having is that the objects supplied from the object spy on screen are NOT JScript objects and you cannot use native JScript to parse them.


     


    What you can use is aqObject which provides properties and methods that allow you to iterate over, and get property values for, Test Completes objects.




    You could then transform the Test Complete objects to native JScript objects which you can pass to json2.js or some other JSON parser.


     


    Regards,


    Phil Baird




  • stephen_araghun's avatar
    stephen_araghun
    Occasional Contributor
    Let me explain further:



    I would like to store objects in an external database so that we can develop mocha tests using these objects running in a Node.JS environment. I would like to serialize the tc object into JSON, and I am able to send that via post to a web server db on local host. However serializing the object into JSON I haven't figured out. external libraries like json2.js also fail on the same for in loop.