Forum Discussion

RK3's avatar
RK3
Occasional Contributor
2 years ago

how to read and validate json file using testcomplete

I have a JSON file want to read and validate that file can you one show me with simple code?
  • rraghvani's avatar
    2 years ago

    Use JSON, here's an example,

     

    function Test1()
    {
        let text = '{ "employees" : [' +
            '{ "firstName":"John" , "lastName":"Doe" },' +
            '{ "firstName":"Anna" , "lastName":"Smith" },' +
            '{ "firstName":"Peter" , "lastName":"Jones" } ]}';
        
        var obj = JSON.parse(text);
        for (var i = 0; i < obj.employees.length; i++) {
            Log.Message(obj.employees[i].firstName);
        }
    }