You might say this is duplicate of this question, but original question WASN'T answered there. Important part of question is: programmatically
?
Is there any php function? Native or homemade?
To beautify your JSON file, you can go to https://jsoneditoronline.org, and paste your JSON there, or load a JSON file from disk or from an url.
Use JSON. stringify(obj) method to convert JavaScript objects into strings and display it. Use JSON. stringify(obj, replacer, space) method to convert JavaScript objects into strings in pretty format.
Open notepad++ -> ALT+P -> Plugin Manager -> Selcet JSON Viewer -> Click Install. Restart notepad++ Now you can use shortcut to format json as CTRL + ALT +SHIFT + M or ALT+P -> Plugin Manager -> JSON Viewer -> Format JSON.
json_encode() has a flag JSON_PRETTY_PRINT
echo json_encode($data, JSON_PRETTY_PRINT);
had the same question right now. But as you also i'm having php < 5.4. Zend Framework has Zend_Json::prettyPrint(). Works very well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With