PHP JSON extension with a new parser
C PHP Yacc Other
Latest commit 8b22837 Dec 30, 2016 @bukka Release 1.4.0RC1
Permalink
Failed to load latest commit information.
bench Add encoding to the simple bench script Oct 12, 2014
phpc @ 58736c4 Use PHPC_OBJ_STD_WRITE_PROPERTY to fix 5.3 build Dec 9, 2016
tests Use dynamic functions in bug69187 test Dec 13, 2016
utils Merge branch 'master' of https://github.com/akmumu/php-jsond into akm… Dec 6, 2016
.gitignore Use jsond prefix by defualt Oct 9, 2016
.gitmodules Add phpc submodule Jan 3, 2016
CREDITS Initial commit with json ext encoder Feb 21, 2014
LICENSE Add LICENSE file Mar 20, 2014
Makefile.frag
README.md Merge branch 'master' of https://github.com/akmumu/php-jsond into akm… Dec 6, 2016
TODO.md Update TODO and UPGRADE Nov 2, 2016
UPGRADE.md Update TODO and UPGRADE Nov 2, 2016
config.m4 Always return error on empty string Oct 20, 2016
config.w32
jsond.c Add fix for bug #72787 Nov 2, 2016
jsond.php Initial commit with json ext encoder Feb 21, 2014
jsond_buffer.c Bump year Jan 2, 2016
jsond_encoder.c Add again label in php_json_encode_zval to PHP 7 only Sep 5, 2016
jsond_parser.tab.c Use PHPC_OBJ_STD_WRITE_PROPERTY to fix 5.3 build Dec 9, 2016
jsond_parser.tab.h Make parser compatible Sep 4, 2016
jsond_parser.y Use PHPC_OBJ_STD_WRITE_PROPERTY to fix 5.3 build Dec 9, 2016
jsond_scanner.c Make <STR_P1>["] compatible Oct 6, 2016
jsond_scanner.re Make <STR_P1>["] compatible Oct 6, 2016
jsond_yacc.c
package.xml Release 1.4.0RC1 Dec 29, 2016
php_jsond.h Release 1.4.0RC1 Dec 29, 2016
php_jsond_buffer.h Add missing buffer destroying for native buffer Sep 25, 2016
php_jsond_encoder.h Bump year Jan 2, 2016
php_jsond_parser.h Use common types for internal decoder functions May 3, 2016
php_jsond_scanner.h Use common types for internal decoder functions May 3, 2016
php_jsond_scanner_defs.h Regenerate json scanner Jul 19, 2015
php_jsond_utf8_decoder.h Make sure that php_json_utf8_decode is always inlined Jun 19, 2015

README.md

PHP JSON extension with new Decoder

The php-jsond is a new JSON parser for PHP

Installation

Linux

PECL

This extension is available on PECL. The package is not currently stable. If the config preferre_state is stable, then the version needs to be specified.

$ sudo pecl install jsond-1.x.y

where x is an installed minor version number and y bug fixing version number.

Manual Installation

It's important to have a git installed as it's necessary for recursive fetch of phpc.

First clone recursively the repository

git clone --recursive https://github.com/bukka/php-jsond.git

Then go to the created directory and compile the extension. The PHP development package has to be installed (command phpize must be available).

cd php-jsond
phpize
./configure
make
sudo make install

Windows

Precompiled binary dll libraries for php-jsond are available on the PECL jsond page.

Documentation

Default API

The functionality is exactly the same as documented in JSON documentation, just the prefixes are different.

Constants

Constants have different prefix (JSOND) than JSON constants but they are the same as the one in PHP 7.

Error constants
JSOND_ERROR_NONE (integer)
JSOND_ERROR_DEPTH (integer)
JSOND_ERROR_STATE_MISMATCH (integer)
JSOND_ERROR_CTRL_CHAR (integer)
JSOND_ERROR_SYNTAX (integer)
JSOND_ERROR_UTF8 (integer)
JSOND_ERROR_RECURSION (integer)
JSOND_ERROR_INF_OR_NAN (integer)
JSOND_ERROR_UNSUPPORTED_TYPE (integer)
JSOND_ERROR_INVALID_PROPERTY_NAME (integer)
JSOND_ERROR_UTF16 (integer)
Encoding constants
JSOND_HEX_TAG (integer)
JSOND_HEX_AMP (integer)
JSOND_HEX_APOS (integer)
JSOND_HEX_QUOT (integer)
JSOND_FORCE_OBJECT (integer)
JSOND_NUMERIC_CHECK (integer)
JSOND_BIGINT_AS_STRING (integer)
JSOND_PRETTY_PRINT (integer)
JSOND_UNESCAPED_SLASHES (integer)
JSOND_UNESCAPED_UNICODE (integer)
JSOND_PARTIAL_OUTPUT_ON_ERROR (integer)
JSOND_PRESERVE_ZERO_FRACTION (integer)
JSOND_VALID_ESCAPE_UNICODE (integer)
Decoding constants
JSOND_OBJECT_AS_ARRAY (integer)
JSOND_BIGINT_AS_STRING (integer)

Functions

The prefix for functions is jsond.

mixed jsond_decode ( string $json [, bool $assoc = false [, int $depth = 512 [, int $options = 0 ]]] );
string jsond_encode ( mixed $value [, int $options = 0 [, int $depth = 512 ]] );
string jsond_last_error_msg ( void );
int jsond_last_error ( void );

The JsondSerializable interface

Prefix for interface is Jsond otherwise it is the same as JsonSerializable.

JsondSerializable {
    /* Methods */
    abstract public mixed jsonSerialize ( void )
}

Drop-in alternative for the standard JSON extension

If jsond is compiled with --enable-jsond-with-json-prefix, than the json functions are replaced with jsond variants and the API is exactly the same as the API documented in JSON documentation.

JSOND IDE Auto Complete

If you use IDE like PhpStorm, you can set the file utils/jsond_auto_complete.php to the Include Path, then IDE will auto complete jsond_encode and jsond_decode.

Upgrading from php-json

All changes are listed in UPGRADE.md

TODO list

The TODO list can be found in TODO.md.