JsonSpread Process

Spread values from json columns

nameIncomeJson
{"name": "John","income": 50000}
{"name": "Marry","income": 60000}
{"name": "Peter","income": 100000}
{"name": "Donald","income": 80000}

->pipe(new JsonSpread(array(
    "nameIncomeJson" => array("name", "income")
)))
nameIncomeJsonnameIncomeJson.namenameIncomeJson.income
{"name": "John","income": 50000} John 50,000
{"name": "Marry","income": 60000} Marry 60,000
{"name": "Peter","income": 100000} Peter 100,000
{"name": "Donald","income": 80000} Donald 80,000

JsonSpread helps to decode json string column and then spread its values into multiple columns. This process is very useful when you want to make calculation bases on the value inside json string.

Spread all values from a json column

->pipe(new JsonSpread(array(
    "nameIncomeJson"
)))

Spread certain values from a json column

->pipe(new JsonSpread(array(
    "nameIncomeJson" => array("name", "income")
)))
<?php
require_once "MyReport.php";

$report = new MyReport;
$report->run()->render();
<?php
//Step 1: Load KoolReport
require_once "../../../load.koolreport.php";

use \koolreport\processes\JsonSpread;

//Step 2: Creating Report class
class MyReport extends \koolreport\KoolReport
{
    protected function settings()
    {
        return array(
            "dataSources"=>array(
                "data"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "dataFormat"=>"table",
                    "data"=>array(
                        array("nameIncomeJson"),
                        array('{"name": "John","income": 50000}'),
                        array('{"name": "Marry","income": 60000}'),
                        array('{"name": "Peter","income": 100000}'),
                        array('{"name": "Donald","income": 80000}'),
                    )
                )
            )
        );
    }
    protected function setup()
    {
        //Prepare data
        $this->src("data")
        ->pipe($this->dataStore("origin"));
        
        //Pipe through process to get result
        $this->src("data")
        ->pipe(new JsonSpread(array(
            "nameIncomeJson"
        )))
        ->pipe($this->dataStore("result"));
    }
}
<?php
    use \koolreport\widgets\koolphp\Table;
    use \koolreport\widgets\google\LineChart;
?>
<div class="report-content">
    <div class="text-center">
        <h1>JsonSpread Process</h1>
        <p class="lead">Spread values from json columns</p>
    </div>
    
    <?php
    Table::create(array(
        "dataSource"=>$this->dataStore("origin"),
        "cssClass"=>array(
            "table"=>"table-bordered table-striped table-hover"
        )
    ));
    ?>

<i class="fa fa-arrow-down" style="font-size:24px;"></i>
<pre style="font-weight:bold"><code>
->pipe(new JsonSpread(array(
    "nameIncomeJson" => array("name", "income")
)))
</code></pre>
<i class="fa fa-arrow-down" style="font-size:24px;"></i>

    <div style="margin-top:20px;">
    <?php
    Table::create(array(
        "dataSource"=>$this->dataStore("result"),
        "cssClass"=>array(
            "table"=>"table-bordered table-striped table-hover"
        )
    ));
    ?>
    </div>

</div>

What People Are Saying

"KoolReport helps me very much in creating data report for my corporate! Keep up your good work!"
-- Alain Melsens

"The first use of your product. I was impressed by its easiness and powerfulness. This product is a great and amazing."
-- Dr. Lew Choy Onn

"Fantastic framework for reporting!"
-- Greg Schneider

Download KoolReport Get KoolReport Pro