We build a PHP script that feeds JSON data to another script. ur script builds data into a large associative array, and then outputs the data using json_encode.
Which is absolutely right. But it’s not enough, the browser needs to understand the type of data, you can specify the header just before echo-ing the data back to the user.
Php Code
header('Content-Type: application/json');
This will result in a well formatted output.
Or, if you like extensions you can use JSONView for Chrome.
How to encode an associative array to a pretty-formatted JSON string, so this doesn’t directly answer the question, but if you have a string that is already in JSON format, you can make it pretty simply by decoding and re-encoding it (requires PHP >= 5.4):
Wikitechy Founder, Author, International Speaker, and Job Consultant. My role as the CEO of Wikitechy, I help businesses build their next generation digital platforms and help with their product innovation and growth strategy. I'm a frequent speaker at tech conferences and events.
easy explanation
easy to understand