PHP Classes

JPOPHP PHP JSON Parser Class: Encode and decode data in JSON format

Recommend this page to a friend!
  Info   View files Example   View files View files (14)   DownloadInstall with Composer Download .zip   Reputation   Support forum (14)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 69%Total: 314 This week: 1All time: 7,265 This week: 571Up
Version Licenses PHP version Categories
jsonparser 2.2.3Custom (specified...5PHP 5, Data types, Parsers
Description 

Author

This package can encode and decode data in JSON format.

It provides a pure PHP solution to take a value and generates a string that represents that value in JSON format.

The package can also take a JSON encoded string and decodes it to retrieve the original data value.

Innovation Award
PHP Programming Innovation award nominee
February 2019
Number 3
PHP comes with built-in support to parse and encode data in the JSON format but it provides limited support to determine if a data JSON string value is well encoded.

This package implements a JSON parse in pure PHP in such a way that is possible to determine more details about errors of a JSON string that is malformed, thus helping developers to validate JSON strings and give the precise location of any errors.

Manuel Lemos
Picture of Max Base
  Performance   Level  
Name: Max Base <contact>
Classes: 5 packages by
Country: United States United States
Age: ???
All time rank: 2613360 in United States United States
Week rank: 420 Up49 in United States United States Up
Innovation award
Innovation award
Nominee: 3x

Winner: 1x

Example

<?php
include "JPOPHP.php";
/* Version: 2.2+ */
print $json->encode([1,2,3,4])."\n";
print
$json->encode([1,2,[94,15,34,67],3,4,["name"=>"max"]])."\n";
print
$json->encode(["name"=>"max","age"=>49,"username"=>"BaseMax"])."\n";
print
$json->encode(["0"=>"max","1"=>49,"2"=>"BaseMax"])."\n";
print
$json->encode([0=>"max",1=>49,2=>"BaseMax"])."\n";
print
$json->encode([0=>"max","1.5"=>49,2=>"BaseMax"])."\n";
print
"\n\n";
print
$json->decode('[]')."\n";
print
$json->decode('{}')."\n";
print
$json->decode('["1"]')."\n";
print
$json->decode('["123456"]')."\n";
print
$json->decode('["hi"]')."\n";
print
$json->decode('["hi\""]')."\n";
print
$json->decode('["hi\"!"]')."\n";
print
$json->decode('[13]')."\n";
print
$json->decode('[134]')."\n";
print
$json->decode('[8]')."\n";
print
$json->decode('[0]')."\n";
print
$json->decode('[-9]')."\n";
print
$json->decode('[-945]')."\n";
print
$json->decode('[3.1]')."\n";
print
$json->decode('[3.145]')."\n";
print_r($json->decode(' [ -3.145,4,"test"]'));
print_r($json->decode(' [ -3.145,4,"test","name":"max"]'));
print_r($json->decode(' [ -3.145,4,"name","max",]'));
print_r($json->decode(' [ -3.145,4,"name","max",,,,,,,]'));
print_r($json->decode(' [,]'));
print_r($json->decode(' [,,,,]'));
print_r($json->decode(' [,,,,4]'));
print_r($json->decode('{}'));
print_r($json->decode('{"a":4,"6":945,,,}'));
print_r($json->decode('{"a":4,"b":456,,,,}'));
print_r($json->decode('{,"a":4,}'));
print_r($json->decode('{,,,"a":4,"b":456,,,,}'));
print_r($json->decode('{,,,,"a":4,,,,,,"6":945,,,}'));
print_r($json->decode('[,,,,]'));
print_r($json->decode('[4]'));
print_r($json->decode(' [,,,,4]'));
print_r($json->decode(' [ , , , , 4]'));
print_r($json->decode(' [ , , , , 4 ] '));
print_r($json->decode(' [ , , , , 4 ] '));
print_r($json->decode("[\n]"));
print_r($json->decode('["max",49,"BaseMax"]'));
print_r($json->decode('[1,[]]'));
print_r($json->decode('[1,[4]]'));
print_r($json->decode('[1,[4,,,6,[8]]]'));
print_r($json->decode('{"name":"Max","line":456,,,,}'));
print_r($json->decode('{"name":"Max","line":456,,,,}'));
// print_r($json->decode('{"name":"Max",4:555,,,,}')); // Error!
print_r($json->decode('[null,false,true]'));
$res=($json->decode('[null,false,true]'));
var_dump($res[1]);
var_dump($res);
var_dump($json->decode('[null,false,true,]'));
print_r($json->decode("[\"45\\\\\"]"));
$arg='["4\\\\"]';
var_dump($arg);
print
$arg."\n";
print_r($json->decode($arg));
print_r($json->decode('["1\u05B5"]'));
print_r($json->decode('["1\u05F1"]'));
print_r($json->decode('["1\u05F"]'));
print_r($json->decode('["1\u05FX"]'));
print_r($json->decode('["1\uM05F"]'));
print_r($json->decode('["1\uM0\'5F"]'));

/* Version: 0 - 2.0
$data=json_encode([1,2,3,4,5,"n\"am':=>[]{}e"=>"ali"]);
$data=json_encode(["name"=>"ali","int"=>110,"float"=>19.98,"-int"=>-110,"-float"=>-19.98,"bool"=>true]);
//$data=json_encode(["name"=>"ali","int"=>110,"float"=>19.98,"-int"=>-110,"-float"=>-19.98,"bool"=>true,"list"=>[1,2,3,4,5]]);
//$data=json_encode(["name"=>"ali","int"=>110,"float"=>19.98,"-int"=>-110,"-float"=>-19.98,"bool"=>true,"list"=>["name"=>"ali","family"=>"ahmadi"]]);
//print $data."\n";
//$array=$json->decode($data);
//$array=$json->decode('{"list":{"name":"ali","family":"ahmadi"}}');
$array=$json->decode('{"list":{"name":"ali","family":"ahmadi"},"age":18}');
//$array=$json->decode('{"name":"ali","int":110,"float":19.98,"-int":-110,"-float":-19.98,"bool":TRUE,"bbb":false}');
print_r($array);
//print_r($json->array);
*/


Details

JPOPHP (Json Parser Object PHP)

Json Parser Object PHP

Tiny Library for parse JSON.

JPOPHP (PHPJsonParser) can encode and decode data in JSON format.

We provides a pure PHP solution to take a value and generates a string that represents that value in JSON format.

The package can also take a JSON encoded string and decodes it to retrieve the original data value.

JsonParser.php File Size JsonParser.min.php File Size JsonParser.php Validation Code

JPOPHP Features

  • Small and light library
  • Hand-coded scanner
  • Analyze and found Errors
  • Unicode Support
  • No dependencies (only suitable version of the `PHP`)
  • Written and run on `PHP 7.2.6`, `PHP 7.3.4`

Type of supported values

  • [x] Integer
  • [x] Float
  • [x] Boolean (`true` , `false`)
  • [x] Null
  • [x] String
  • [x] Char (Now this is same as a string)
  • [x] Sub Array
  • [x] Sub Object

JPOPHP TODO

  • Improve speed and performance (Speed does not reach `C Language`!)

Usage

All public functions are accessible through the $json variable.

  • `array $json->decode(string);`
  • `string $json->encode(array);`

Samples

To view the full details, run the Example.php file.

JSON Grammar

You can check the JSONGrammar.txt file to view the JSON standard grammar.

JPO-PHP Performance

Competition between json_encode(...) and $json->encode(...)

The basic PHP functions are written in C itself.

Do not expect to reach it quickly.

However, there is always way for improvement.

JPO PHP History

  • Version 1.0 (first) : 2018-06-26 - 2018-06-26
  • Version 2.1 : 2018-06-27 - 2019-03-13
  • Version 2.2 : 2019-03-25 - 2019-04-03
  • Version 2.2.1 : 2019-04-04

License

JsonParser (PHP JSON Parser) is licensed under the GNU General Public License.


  Files folder image Files  
File Role Description
Accessible without login Plain text file Benchmark.md Data Auxiliary data
Accessible without login Plain text file composer.json Data This package has been released in Composer.
Accessible without login Plain text file Example.php Example Example script
Plain text file JPOPHP-min.php Class Class source
Plain text file JPOPHP-min.php Class Class source
Plain text file JPOPHP.php Class Class source
Plain text file JPOPHP.php Class Class source
Accessible without login Plain text file JSONGrammar.txt Doc. Documentation
Plain text file JsonParser-min.php Class The compressed file was added.
Plain text file JsonParser.php Class Class source
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file Performance-own.php Example Example script
Accessible without login Plain text file Performance-php.php Aux. Auxiliary script
Accessible without login Plain text file README.md Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 71%
Total:314
This week:1
All time:7,265
This week:571Up
User Ratings User Comments (13)
 All time
Utility:83%StarStarStarStarStar
Consistency:91%StarStarStarStarStar
Documentation:91%StarStarStarStarStar
Examples:91%StarStarStarStarStar
Tests:-
Videos:-
Overall:69%StarStarStarStar
Rank:354