Posts

Showing posts with the label json

Json_encode function to print php json indent

Image
When encoding an associative array to json using the json_encode function in php, it is output as a single line without indentation. <?php $arr[ 'user' ] = "kim" ; $arr[ 'age' ] = "15" ; $arr[ 'phone_number' ] = "1111-1111" ; echo json_encode($arr); ?> Results If the JSON is long, you can use a site that sorts JSON because it is very hard to see. https://jsonformatter.curiousconcept.com/   JSON Formatter & Validator Format and validate JSON data so that it can easily be read by human beings. jsonformatter.curiousconcept.com This json encoding process is provided in php's json_encode by default. Just give JSON_PRETTY_PRINT as the second argument of json_encode. This argument has been supported since php 5.4. <?php $arr[ 'user' ] = "kim" ; $arr[ 'age' ] = "15" ; $arr[ 'phone_number...