Vinaya Maheshwari Vinaya Maheshwari - 1 year ago 78
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?

Answer Source

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');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download