Reputation: 1159
I have a url which returns a formatted JSON. The problem is when I am echoing the $json, the json is losing its formatting. How would I avoid that
I am doing this
$query_string_full = http://this_is_a_dummyString.htm?key=123&ID=abc123;
$json = file_get_contents($query_string_full);
$obj = json_decode(stripslashes($json));
echo $obj;
Here is the output http://soumghosh.com/otherProjects/phpDataOperation/eventcCalendar/ajax.php
I found couple of similar problems of this nature but unfortunately none of them really worked. One them is using the stripslashes. Maybe I am not using it correctly?
Upvotes: 0
Views: 72
Reputation: 14479
What you're echoing should be an object or an array, since that's what json_decode()
would return.
Try this:
$query_string_full = http://this_is_a_dummyString.htm?key=123&ID=abc123;
$json = file_get_contents($query_string_full);
$obj = json_decode($json);
echo '<pre>'. json_encode($obj, JSON_PRETTY_PRINT) .'</pre>';
Upvotes: 1