I have created a webservice and return data in json but on API testing site showing response not in formatted form.
My code is as below :
return json_encode(array("Data" => array("data" => "hello","data2" => "hello1")),JSON_PRETTY_PRINT);
Give a try to
return json_encode($data, JSON_PRETTY_PRINT);
This will give your preet print. Also what you have done should be working fine but what could be wrong is you are missing the json header.