Output human-readable JSON with PHP

Working with the Zencoder API I wanted to check my JSON before attempting to submit it – easy enough to output, but to read?

To the Google! Turns up trumps with http://www.webdeveloper.com/forum/showthread.php?t=235140 where user janusmcarthy has provided this nifty little function. Pretty much the way I’d have done it, but didn’t want to spend the time writing.

strip_html_tags() Function

3 thoughts on “Output human-readable JSON with PHP”

  1. Just wanted to let you know that your code fails if the last dtwo letters in a string are \ which basically is allowed.To make a correct code, you will parse backwards, count the and if they are odd, you will use your code, if not, just add the char to the newjson string

Leave a Reply

Your email address will not be published. Required fields are marked *