convert API response : I am making AJAX call and getting response 



    console.log(data);
    {"valid":true,"when":"Today"}

when I try to read it


    var res = data.valid;
    console.log(res);
it shows undefined . I am trying to add a condition 



    if(res==true){
    /*code*/
    }
