rfc:free-json-parser

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:free-json-parser [2013/08/25 16:49] – [Proposed PHP Version(s)] remirfc:free-json-parser [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
  
 ====== PHP RFC: Switch from json extension to jsonc ====== ====== PHP RFC: Switch from json extension to jsonc ======
-  * Version: 0.1+  * Version: 1.0
   * Date: 2013-08-25   * Date: 2013-08-25
   * Author: Remi Collet <remi@php.net>   * Author: Remi Collet <remi@php.net>
-  * Status: Draft (or Under Discussion or Accepted or Declined)+  * Status: Under Discussion (or Accepted or Declined)
   * First Published at: https://wiki.php.net/rfc/free-json-parser   * First Published at: https://wiki.php.net/rfc/free-json-parser
  
Line 15: Line 15:
 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. 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 ([[https://bugs.php.net/id=63588|Bug #63588]])+The encoder code is free since PHP 5.4.10 ([[https://bugs.php.net/63588|Bug #63588]])
  
 ===== Proposal ===== ===== Proposal =====
  
-The extension jsonc extension, currently available from PECL site is designed to be a dropin alternative.  +The **jsonc** extension, currently available from PECL site is designed to be a dropin alternative (same user API and internal ABI for other extensions)
-  * Same encoder than PHP 5.5 +  * Same **encoder** as in PHP 5.5 
-  * Parser provided by the [[https://github.com/json-c/json-c|json-c]] library (License MIT)+  * **Parser** provided by the [[https://github.com/json-c/json-c|json-c]] library (License MIT). Build can use the system library (--with-libjson) or the bundled copy (currently version 0.11 + some patches waiting for upstream review)
  
-As the new parser is an incremental onenew **JsonIncrementalParser** class expose this feature+While the main purpose of this RFC is to fix the Licensing issueit also introduce some new features.
  
 +As the new parser is an incremental one, the new **JsonIncrementalParser** class expose this feature
  
 <code> <code>
Line 34: Line 35:
 } while ($buf && ($ret==JsonIncrementalParser::JSON_PARSER_CONTINUE)); } while ($buf && ($ret==JsonIncrementalParser::JSON_PARSER_CONTINUE));
 $result = $parser->get(); $result = $parser->get();
 +</code>
 +
 +Or, allow to parse a file without having to load it into memory:
 +<code>
 +$parser = new JsonIncrementalParser();
 +$ret = $parser->parseFile("somefile.json");
 +$result = $parser->get();
 +</code>
 +
 +The json-c parser provides 2 strictness mode:
 +  * strict mode, used by default (for compatibility with previous implementation)
 +  * standard mode, available using the JSON_PARSER_NOTSTRICT option
 +
 +Having a **not-strict parser** could be usefull for reading configuration from manually edited file, such as:
 +<code>
 +/*
 +Foo configuration file
 +*/
 +{
 +    "temp": "/tmp", // directory
 +    "debug": true,  // boolean
 +}
 </code> </code>
  
 ===== Backward Incompatible Changes ===== ===== 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 "naturalencoder will generate such data.+Partial implementation of big integers parsing (and of JSON_BIGINT_AS_STRING option). This will only work in a 32bits build 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. 
 + 
 +As the new parser implement different error codes, parser error is always returned by **json_last_error()** as JSON_ERROR_SYNTAX (JSON_ERROR_STATE_MISMATCH and JSON_ERROR_CTRL_CHAR are kept for compatibility but never used). 
 + 
 +**json_last_error_msg()** returns error string from the json-c library. 
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
Line 48: Line 76:
   * **Debian** since PHP 5.5 / Jessie   * **Debian** since PHP 5.5 / Jessie
   * **Fedora** since PHP 5.5 / Fedora 19   * **Fedora** since PHP 5.5 / Fedora 19
-  * **Mageia**+  * **Mageia** since PHP 5.5
   * **Ubuntu** since PHP 5.5 / Saucy   * **Ubuntu** since PHP 5.5 / Saucy
  
Line 57: Line 85:
 ===== Impact to Existing Extensions ===== ===== Impact to Existing Extensions =====
  
-  * replace json extension by jsonc+  * replace json extension by jsonc (of course, renamed to json)
  
 ===== New Constants ===== ===== New Constants =====
  
 JSON_PARSER_NOTSTRICT which allow to reduce parser strictness JSON_PARSER_NOTSTRICT which allow to reduce parser strictness
-* comment are allowed +  * comment are allowed 
-* trailing char after data are ignored +  * trailing char after data are ignored 
-* trailing coma in list are ignored +  * trailing coma in list are ignored 
-* etc+  * etc
  
 JSON_C_BUNDLED boolean, true if bundled json-c library is used, false if system one JSON_C_BUNDLED boolean, true if bundled json-c library is used, false if system one
Line 77: Line 105:
 ===== Unaffected PHP Functionality ===== ===== Unaffected PHP Functionality =====
  
-List existing areas/features of PHP that will not be changed by the RFC+No change in PHP engine
- +No change for other extension.
-This helps avoid any ambiguity, shows that you have thought deeply about the RFC's impact, and helps reduces mail list noise.+
  
 ===== Future Scope ===== ===== Future Scope =====
  
-This sections details areas where the feature might be improved in futurebut that are not currently proposed in this RFC.+Speed improvment. 
 + 
 +As the original author (omar) seems no more involedI could maintain this extension in the future.
  
 +Implement some RFE such as [[https://bugs.php.net/bug.php?id=65082|Bug #65082 new option for replacing ill-formed byte sequences with substitute char]]
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
  
-Include these so readers know where you are heading and can discuss the proposed voting options.+  * Yes (switch from json to jsonc in php 5.6) 
 +  * No (keep using non-free stuff in php)
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
rfc/free-json-parser.1377449341.txt.gz · Last modified: 2017/09/22 13:28 (external edit)