PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Pretty-printing JSON

Sometimes, it may be hard to explore JSON data generated by Zend_Json::encode(), since it has no spacing or indentation. In order to make it easier, Zend_Json allows you to pretty-print JSON data in the human-readable format with Zend_Json::prettyPrint().

<?php
// Encode it to return to the client:
$json Zend_Json::encode($phpNative);
if(
$debug) {
    echo 
Zend_Json::prettyPrint($json, array("indent" => " "));
}

Second optional argument of Zend_Json::prettyPrint() is an option array. Option indent allows to set indentation string - by default it's a single tab character.

Zend Framework