PHP Classes

PHP WWJSON: Convert JSON data into other formats

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 46 All time: 10,788 This week: 560Up
Version License PHP version Categories
wwjson 1.0.0Custom (specified...5PHP 5, Data types
Description 

Author

This class can convert JSON data into other formats. Currently it can:

- Encrypt and decrypt JSON data
- Convert JSON object to an array
- Convert JSON object to an array of entries with the path of the each value as index
- Convert JSON object to flat array
- etc.

Picture of zinsou A.A.E.Moïse
  Performance   Level  
Name: zinsou A.A.E.Moïse <contact>
Classes: 50 packages by
Country: Benin Benin
Innovation award
Innovation award
Nominee: 23x

Winner: 2x

Example

<?php
require_once('Pson.class.php');
echo
'<h1>Play with JSON and PHP array</h1>';
echo
'<h2>how to use</h2>';
$x=new Pson();
echo(
$x);
var_dump($x());

$x='{
    ":database":{
        ":crud-action":"create",
        "name":"another_unify_schools",

        ":table-group":[
            {
                ":crud-action":"create",
                "name":"students",
                "columns":[
                    {
                        "name":"id",
                        "data-type":"int",
                        "primary-key":true
                    },
                    {
                        "name":"first_name",
                        "data-type":"varchar(20)",
                        "default":"\'samuel\'"
                    },
                    {
                        "name":"last_name",
                        "data-type":"varchar(20)"
                    },
                    {
                        "name":"class",
                        "data-type":"varchar(10)"
                    }
                ]
            },
            {
                ":crud-action":"create",
                "name":"faculty",
                "columns":[
                    {
                        "name":"fac_id",
                        "data-type":"int",
                        "auto_increment":true,
                        "primary-key":true
                    },
                    {
                        "name":"first_name",
                        "data-type":"varchar(20)"
                    },
                    {
                        "name":"last_name",
                        "data-type":"varchar(20)"
                    }
                ]
            },
            {
                ":crud-action":"create",
                "name":"subjects",
                "columns":[
                    {
                        "name":"subject_id",
                        "data-type":"int",
                        "auto_increment":true,
                        "primary-key":true
                    },
                    {
                        "name":"subject_name",
                        "data-type":"varchar(30)"
                    },
                    {
                        "name":"subject_faculty",
                        "data-type":"int",
                        "foreign-key":"(subject_faculty)",
                        "references":"faculty(fac_id)",
                        "on-update":"cascade",
                        "on-delete":"set null"
                    }
                ]
            }
        ]
    }
}'
;

echo
'<pre>';
echo
'<h2>json to really simple array</h2>';
print_r( Pson::json_toarray($x));
echo
'<h2>json to simple flatten array </h2>';
print_r( $r=Pson::json_toFlatten($x));
echo
'<h2>Flatten array to multidimensionnal array encoded in json</h2>';
print_r( Pson::Flatten_toMulti_json($r));
echo
'<h2>Encrypted PHP variable built from json</h2>';
print_r($e=Pson:: phpArray_son($x,false,true));
$i=explode('::',$e["key"]);
echo
'<h2>Decrypt encrypted PHP variable built from json</h2>';
print_r(Pson::unserialize_Pason($e["encrypted"],$i));
echo
'<h2>Encrypt Json</h2>';
print_r($t=Pson::json_crypt($x));
echo
'<h2>Decrypt encrypted Json</h2>';
print(
Pson::cjson_decrypt($t));
echo
'<h2> Unserialize serialized PHP Array built from Json</h2>';
print_r(Pson::unserialize_Pason(Pson::phpArray_son($x,false,false)));
echo
'<h2>convert to PHP Array, serialize,Encrypt and save to a file from Json</h2>';
Pson::phpArray_son($x,'test',true);
echo
'<h2>Unserialize serialized and encrypted PHP Array built from Json</h2>';
print_r(Pson::unserialize_Pason('test.pason','test.pason.key'));
echo
'<h2>serialized and encrypted PHP Array to Json</h2>';
print_r(Pson::Pason_toJson('test.pason','test.pason.key'));
echo
'</pre>';



?>


Details

Pson class is a wrapper for some functions usefull for working on JSON or PHP ARRAY Actually it can encrypt and decrypt JSON , build a Flatten array from multidimensionnal array in JSON Format and reverse it when needed It can also convert JSON in a ready to use serialized PHP variable that can be encrypted , save in array or a file for future usage See the file Pson.class.php for more explanations and the file testPson.php for an example of how to use Bug report and feedback to leizmo@gmail.com or in the PHP classes dedicated forum....

  Files folder image Files (4)  
File Role Description
Accessible without login Plain text file license.txt Lic. license file
Plain text file Pson.class.php Class class source
Accessible without login Plain text file readme.txt Doc. readme
Accessible without login Plain text file testPson.php Example example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:46
This week:0
All time:10,788
This week:560Up