PHP Classes

PHP JSON Pretty Print: Display data types like human-readable JSON values

Recommend this page to a friend!
  Info   View files Example   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 141 This week: 1All time: 9,190 This week: 560Up
Version License PHP version Categories
json_formatter 1.0.0BSD License5HTML, PHP 5, Data types
Description 

Author

This class can display data types like human-readable JSON values.

It takes the a variable value as parameter and encodes it as JSON object.

The class processes the JSON output and reformats it to display nicely in a HTML Web page.

Innovation Award
PHP Programming Innovation award nominee
July 2019
Number 10
Many developers need to check values used in their applications variables. One easy way of seeing those values is to display them on a Web page.

Nowadays, many developers prefer to use the JSON format to display application variable values. PHP supports the JSON format but sometimes the output of the JSON encoding functions is not very readable.

This class provides a solution to display application variable values using the JSON format in a way that can be more readable for all developers.

Manuel Lemos
Picture of chrys ugwu
  Performance   Level  
Name: chrys ugwu <contact>
Classes: 16 packages by
Country: Nigeria Nigeria
Age: 30
All time rank: 16897 in Nigeria Nigeria
Week rank: 416 Up8 in Nigeria Nigeria Down
Innovation award
Innovation award
Nominee: 4x

Example

<?php
require 'src/Json.php';

Json::setBreak('<br>');
Json::setIndent('<span style=\'margin-left:20px;display:block\'>', '</span>');
Json::allowFont(true, 'Lucida Console, Monaco, monospace');

$source = array (
  array (
'points' => 1, 'name' => 'Peter'),
  array (
'points' => 5, 'name' => 'Mike'),
  array (
'points' => 2, 'name' => 'John Zoo'),
  array (
'points' => 2, 'name' => 'John Ab')
);

echo
Json::encode($source);

?>


Details

JSON_Formatter

Allows you to pretty-print JSON data in a human-readable format

Latest Stable Version License Latest Stable Version Minimum PHP Version

Installation

You can download the Latest release version as a standalone, alternatively you can use Composer for optional dependencies such as PHPUnit.

$ composer require ghostff/json-formatter

Or add:

{
    "require": {
        "ghostff/json-formatter": "^1.0"
    }
}

to your `composer.json`

Usage:

<?php

$source = array (
  array ( 'points' => 1, 'name' => 'Peter'),
  array ( 'points' => 5, 'name' => 'Mike'),
  array ( 'points' => 2, 'name' => 'John Zoo'),
  array ( 'points' => 2, 'name' => 'John Ab')
);

echo Json::encode($source);

Outputs:

alt tag


  Files folder image Files  
File Role Description
Files folder imagesrc (1 file)
Plain text file composer.json Data Auxiliary data
Plain text file index.php Example Example
Plain text file README.md Doc. Documentation
Image file SS.png Data Auxiliary data
Plain text file text.php Aux. Auxiliary script

  Files folder image Files  /  src  
File Role Description
  Plain text file Json.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:141
This week:1
All time:9,190
This week:560Up