rfc:free-json-parser

This is an old revision of the document!


PHP RFC: Switch from json extension to jsonc

Introduction

Since PHP 5.2.0, JSON format support is provided by ext/json.

During a code license review, Debian project have discovered a issue with the code used, reported as Bug #63520.

Effectively, code from json.org is not free, as its License includes a restriction to freedom 0 (run the program for any purpose) : “The Software shall be used for Good, not Evil”. The discussion about this state is out of the scope of this RFC.

The encoder code is free since PHP 5.4.10 (Bug #63588)

Proposal

The extension jsonc extension, currently available from PECL site is designed to be a dropin alternative.

  • Same encoder than PHP 5.5
  • Parser provided by the json-c library (License MIT)

As the new parser is an incremental one, a new JsonIncrementalParser class expose this feature

$parser = new JsonIncrementalParser();
$fic = fopen("somefile.json", "r");
do {
    $buf = fgets($fic);
    $ret = $parser->parse($buf);
} while ($buf && ($ret==JsonIncrementalParser::JSON_PARSER_CONTINUE));
$result = $parser->get();

Backward Incompatible Changes

Partial implementation of big integers parsing (and of JSON_BIGINT_AS_STRING option). This will only work in a 32bits version for value fitting in a 64bits integer (not managed by PHP, so returned as string or float). Notice: no “natural” encoder will generate such data.

Proposed PHP Version(s)

PHP 5.6

Notice pecl/jsonc extension is already adopted by various Linux distributions which cannot provide non-free code.

  • Debian since PHP 5.5 / Jessie
  • Fedora since PHP 5.5 / Fedora 19
  • Mageia
  • Ubuntu since PHP 5.5 / Saucy

SAPIs Impacted

All

Impact to Existing Extensions

  • replace json extension by jsonc

New Constants

JSON_PARSER_NOTSTRICT which allow to reduce parser strictness

  • comment are allowed
  • trailing char after data are ignored
  • trailing coma in list are ignored
  • etc

JSON_C_BUNDLED boolean, true if bundled json-c library is used, false if system one

JSON_C_VERSION version of the json-c library

Open Issues

None

Unaffected PHP Functionality

List existing areas/features of PHP that will not be changed by the RFC.

This helps avoid any ambiguity, shows that you have thought deeply about the RFC's impact, and helps reduces mail list noise.

Future Scope

Speed improvment.

Proposed Voting Choices

Include these so readers know where you are heading and can discuss the proposed voting options.

Patches and Tests

Current sources: https://github.com/remicollet/pecl-json-c

Notice : the test suite from the original json extension is kept. New features have new tests.

Implementation

References

Rejected Features

Keep this updated with features that were discussed on the mail lists.

rfc/free-json-parser.1377449433.txt.gz · Last modified: 2017/09/22 13:28 (external edit)