Vinaya Maheshwari Vinaya Maheshwari - 4 months ago 6x
PHP Question

How to format json data in php

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);

enter image description here

How to get it?


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.

header('Content-Type: application/json');