Transform a PHP array into JSON string

Server-side (PHP):

echo json_encode($array_data,JSON_PARTIAL_OUTPUT_ON_ERROR);

Client-side (AJAX JQuery):

$.ajax({ url:'', method:'post', data:{ a:a, b:b} }).done((ans)=>{
   try{ 
      var anns = JSON.parse(ans);   
   } catch(e){ 
      console.log('AJAX exception'); 
      console.log(e); 
   }
}).fail(()=>{}).always(()=>{});

or simply add dataType:

$.ajax({ url:'', method:'post', dataType:'JSON', data:{ a:a, b:b} }).done((ans)=>{
    console.log(ans);
}).fail(()=>{}).always(()=>{});